Crate titanium_gateway

Crate titanium_gateway 

Source
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.
ClusterConfig
Configuration for a Cluster.
ConnectionProperties
Connection properties sent with Identify.
GatewayMetrics
Metrics for the entire Gateway cluster.
GatewayPayload
A fully parsed Gateway payload.
HelloPayload
Payload for the Hello opcode (op 10).
IdentifyPayload
Payload for the Identify opcode (op 2).
IdentifyRateLimiter
Rate limiter for Gateway identify operations.
ReadyEvent
Payload for the READY dispatch event.
ResumePayload
Payload for the Resume opcode (op 6).
Shard
A Discord Gateway shard.
ShardConfig
Configuration for a shard.
ShardMetrics
Metrics for a single shard.
ZlibDecompressor
Zlib-stream decompressor for Gateway messages.
ZlibTransport
Transport-level zlib compression (per-message).

Enums§

OpCode
Discord Gateway operation codes.
ShardRange
Specifies which shards a Cluster should manage.
ShardState
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.