titanium_gateway/
lib.rs

1//! Titan Gateway - High-performance Discord Gateway WebSocket client
2#![deny(unsafe_code)]
3//!
4//! This crate provides a robust WebSocket client for Discord's Gateway API,
5//! designed for bots scaling to 1M+ guilds.
6//!
7//! # Features
8//!
9//! - Zero-copy JSON parsing with optional SIMD acceleration
10//! - ETF (Erlang Term Format) support for smaller payloads
11//! - Automatic heartbeat management
12//! - Session resumption support
13//! - Cluster-native shard management
14//! - Strict error handling (no unwrap)
15//!
16//! # Cargo Features
17//!
18//! - `simd` - Enable SIMD-accelerated JSON parsing (~2-3x faster on supported CPUs)
19//! - `etf` - Enable Erlang Term Format encoding (more compact than JSON)
20//!
21//! # Example
22//!
23//! ```ignore
24//! use titanium_gateway::{Shard, ShardConfig};
25//! use titanium_model::Intents;
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
29//!     let config = ShardConfig::new("your-token", Intents::default());
30//!     let mut shard = Shard::new(0, 1, config);
31//!     
32//!     let (event_tx, event_rx) = flume::unbounded();
33//!     shard.run(event_tx).await?;
34//!     
35//!     Ok(())
36//! }
37//! ```
38mod cluster;
39mod compression;
40pub mod error;
41pub mod etf;
42pub mod event;
43pub mod heartbeat;
44mod metrics;
45mod opcode;
46mod parsing;
47mod payload;
48mod ratelimit;
49mod shard;
50
51// Public re-exports
52pub use cluster::{Cluster, ClusterConfig, ShardRange};
53pub use compression::{ZlibDecompressor, ZlibTransport};
54pub use error::GatewayError;
55pub use etf::{EtfDecoder, EtfTerm, GatewayEncoding};
56pub use event::Event;
57pub use metrics::{GatewayMetrics, ShardMetrics};
58pub use opcode::OpCode;
59pub use parsing::{from_str, from_string, to_string};
60pub use payload::{
61    ConnectionProperties, GatewayPayload, HelloPayload, IdentifyPayload, ReadyEvent, ResumePayload,
62};
63pub use ratelimit::IdentifyRateLimiter;
64pub use shard::{Shard, ShardConfig, ShardState};
65
66/// Discord Gateway API version used by this library.
67pub const GATEWAY_VERSION: u8 = 10;
68
69/// Default gateway URL (will be overridden by /gateway/bot response).
70pub const DEFAULT_GATEWAY_URL: &str = "wss://gateway.discord.gg";