Skip to content

Latest commit

 

History

History
93 lines (52 loc) · 2.62 KB

File metadata and controls

93 lines (52 loc) · 2.62 KB

Datrope

Strict types for Discord's not-so-strict API and Gateway. serde is used for (de)serialization.

How to use

Get set up with Rust and add this library as a dependency to your project:

cargo add datrope

Features

The library size and compile time can be reduced by turning off the default feature and enabling just what you need.

Example:

# Cargo.toml

[dependencies]
datrope = { version = "*", default-features = false, features = ["all_objects", "serde"] }

default

Enables: api, gateway, clone, debug, and serde

The default feature set aimed at Just Working™ for the majority of users, at the cost of slower compile times.

api

Enables: api_objects and serde

The API client to make HTTP requests to various endpoints.

api_objects

Objects returned from and sent to the Discord API. This feature is intended for folks wanting to implement their own API client. If serde is enabled, all objects will implement Serialize and Deserialize.

gateway

Enables: gateway_objects, serde, and api

The Gateway client to handle events sent to and received from the Discord Gateway.

gateway_objects

Enables: api_objects

Objects returned from and sent to the Discord Gateway. This feature is intended for folks wanting to implement their own Gateway client. If serde is enabled, all objects will implement Serialize and Deserialize.

all_objects

Enables: api_objects and gateway_objects

Objects returned from and sent to the Discord API and Gateway. This feature is intended for folks wanting to implement their own API and Gateway clients.

undocumented-fields

Enables fields returned by the Discord API or Gateway that are not documented by Discord. These may change at any time.

clone

Will derive Clone for all objects.

debug

Will derive Debug for all objects.

serde

Enables: dep:serde, dep:serde_json, dep:serde_repr, enumset/serde, time/serde, time/formatting, time/parsing, and url/serde

Deserializing

For any JSON you receive from the API or Gateway (use whichever type applies for the endpoint you're receiving data from):

let payload: EventPayload = serde_json::from_str(&message)?;

Serializing

When sending data to the API or Gateway, build the data and convert to JSON:

let message = EventPayload::Heartbeat(None);
let json = serde_json::to_string(&message);