Strict types for Discord's not-so-strict API and Gateway.
serde is used for (de)serialization.
Get set up with Rust and add this library as a dependency to your project:
cargo add datropeThe 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"] }
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.
Enables: api_objects and serde
The API client to make HTTP requests to various endpoints.
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.
Enables: gateway_objects, serde, and api
The Gateway client to handle events sent to and received from the Discord Gateway.
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.
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.
Enables fields returned by the Discord API or Gateway that are not documented by Discord. These may change at any time.
Will derive Clone for all objects.
Will derive Debug for all objects.
Enables: dep:serde, dep:serde_json, dep:serde_repr, enumset/serde, time/serde, time/formatting, time/parsing, and url/serde
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)?;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);