ghost_sync/
lib.rs

1//! # ghost-sync [GitHub](https://github.com/ronakgh97/ghost-sync)
2//!
3//! A composable Tokio TCP relay for room-based multiplayer messaging.
4//!
5//! `ghost-sync` provides a lightweight, backpressure-aware server and an asynchronous client for
6//! building real-time multiplayer applications where state sync is managed explicitly via rooms.
7//!
8//! ## Features
9//!
10//! - **Room Management**: Clients join isolated rooms. All messages within a room are broadcast to all connected peers.
11//! - **Efficient Broadcasts**: Messages are serialized exactly once per room and zero-copy shared among all recipients.
12//! - **Backpressure**: Prevents slow clients from consuming unbounded server memory via drop-on-full semantics. Hook into backpressure events via [`ServerHandler::on_backpressure`].
13//! - **Custom Handlers**: Inject your own application logic using the [`ServerHandler`] trait (e.g., `on_connect`, `on_join`, `on_leave`, `on_broadcast`).
14//!
15//! ## Quick Examples
16//!
17//! ### Server
18//! ```rust,no_run
19//! use ghost_sync::{Server, NoopHandler};
20//!
21//! #[tokio::main]
22//! async fn main() {
23//!     let server = Server::builder()
24//!         .bind("127.0.0.1:8080")
25//!         .handler(NoopHandler)
26//!         .build();
27//!
28//!     // Creates a background task running the server
29//!     let handle = server.run().await.unwrap();
30//!
31//!     // Keep the server alive
32//!     std::future::pending::<()>().await;
33//! }
34//! ```
35//!
36//! ### Client
37//! ```rust,no_run
38//! use ghost_sync::{Client, ServerEvent};
39//!
40//! #[tokio::main]
41//! async fn main() {
42//!     let mut client = Client::connect("127.0.0.1:8080").await.unwrap();
43//!
44//!     // Join a room to start receiving and sending broadcasts
45//!     client.join("test-room", None).await.unwrap();
46//!
47//!     while let Ok(Some(event)) = client.recv().await {
48//!         match event {
49//!             ServerEvent::Joined { client_id, room_id } => println!("Joined room: {}", room_id),
50//!             ServerEvent::Broadcast { sender_id, data } => {
51//!                 println!("Received broadcast: {:?}", data);
52//!             },
53//!             _ => {}
54//!         }
55//!     }
56//! }
57//! ```
58
59#![allow(deprecated)]
60mod client;
61mod handler;
62pub mod log;
63mod protocol;
64mod room;
65mod server;
66mod storage;
67mod types;
68
69pub use client::{Client, ClientBuilder};
70pub use handler::{NoopHandler, ServerHandler};
71pub use log::*;
72pub use server::{Server, ServerBuilder, ServerHandle};
73pub use types::{Result, ServerConfig, ServerEvent, SyncError};
74
75pub use uuid::Uuid;