Expand description
Titan Gateway - High-performance Discord Gateway WebSocket client
This crate provides a robust WebSocket client for Discord’s Gateway API, designed for bots scaling to 1M+ guilds.
§Features
- Zero-copy JSON parsing with optional SIMD acceleration
- ETF (Erlang Term Format) support for smaller payloads
- Automatic heartbeat management
- Session resumption support
- Cluster-native shard management
- Strict error handling (no unwrap)
§Cargo Features
simd- Enable SIMD-accelerated JSON parsing (~2-3x faster on supported CPUs)etf- Enable Erlang Term Format encoding (more compact than JSON)
§Example
ⓘ
use titanium_gateway::{Shard, ShardConfig};
use titanium_model::Intents;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ShardConfig::new("your-token", Intents::default());
let mut shard = Shard::new(0, 1, config);
let (event_tx, event_rx) = flume::unbounded();
shard.run(event_tx).await?;
Ok(())
}Re-exports§
pub use error::GatewayError;pub use etf::EtfDecoder;pub use etf::EtfTerm;pub use etf::GatewayEncoding;pub use event::Event;
Modules§
- error
- Gateway error types using thiserror.
- etf
- Erlang Term Format (ETF) decoder for Discord Gateway.
- event
- Gateway event parsing and dispatch.
- heartbeat
Structs§
- Cluster
- A Cluster manages multiple Gateway Shards.
- Cluster
Config - Configuration for a Cluster.
- Connection
Properties - Connection properties sent with Identify.
- Gateway
Metrics - Metrics for the entire Gateway cluster.
- Gateway
Payload - A fully parsed Gateway payload.
- Hello
Payload - Payload for the Hello opcode (op 10).
- Identify
Payload - Payload for the Identify opcode (op 2).
- Identify
Rate Limiter - Rate limiter for Gateway identify operations.
- Ready
Event - Payload for the READY dispatch event.
- Resume
Payload - Payload for the Resume opcode (op 6).
- Shard
- A Discord Gateway shard.
- Shard
Config - Configuration for a shard.
- Shard
Metrics - Metrics for a single shard.
- Zlib
Decompressor - Zlib-stream decompressor for Gateway messages.
- Zlib
Transport - Transport-level zlib compression (per-message).
Enums§
- OpCode
- Discord Gateway operation codes.
- Shard
Range - Specifies which shards a Cluster should manage.
- Shard
State - Shard connection state.
Constants§
- DEFAULT_
GATEWAY_ URL - Default gateway URL (will be overridden by /gateway/bot response).
- GATEWAY_
VERSION - Discord Gateway API version used by this library.
Functions§
- from_
str - Parse JSON from a string slice.
- from_
string - Parse JSON from owned String, consuming it.
- to_
string - Serialize a value to a JSON string.