wynd/lib.rs
1#![warn(missing_docs)]
2
3//! # Wynd - A Simple WebSocket Library for Rust
4//!
5//! Wynd is a lightweight, async WebSocket server library built on Tokio and Tungstenite,
6//! designed to provide an excellent developer experience for building WebSocket applications in Rust.
7//!
8//! ## Features
9//!
10//! - **Simple API**: Easy-to-use event-driven API with async/await support
11//! - **Type Safety**: Strongly typed message events and error handling
12//! - **High Performance**: Built on Tokio for excellent async performance
13//! - **Connection Management**: Automatic connection lifecycle management
14//! - **Error Handling**: Comprehensive error handling with custom error types
15//!
16//! ## Quick Start
17//!
18//! ```rust
19//! use wynd::wynd::Wynd;
20//!
21//! #[tokio::main]
22//! async fn main() {
23//! let mut wynd = Wynd::new();
24//!
25//! wynd.on_connection(|conn| async move {
26//! println!("New connection established: {}", conn.id());
27//!
28//! conn.on_open(|handle| async move {
29//! println!("Connection {} is now open", handle.id());
30//! })
31//! .await;
32//!
33//! conn.on_text(|msg, handle| async move {
34//! println!("Message received: {}", msg.data);
35//! // Echo the message back
36//! let _ = handle.send_text(&msg.data).await;
37//! });
38//! });
39//!
40//! wynd.listen(8080, || {
41//! println!("Listening on port 8080");
42//! });
43//! //.await
44//! //.unwrap();
45//! }
46//! ```
47//!
48//! ## Core Concepts
49//!
50//! - **Wynd**: The main server instance that manages connections and handles server-level events
51//! - **Connection**: Represents an individual WebSocket connection with event handlers
52//! - **ConnectionHandle**: Provides methods to interact with a connection (send messages, close, etc.)
53//! - **Events**: Typed events for different WebSocket message types (text, binary, close, error)
54//!
55//! ## Examples
56//!
57//! See the `examples/` directory for more comprehensive examples:
58//!
59//! - Basic echo server
60//! - Chat room implementation
61//! - Binary data handling
62//! - Error handling patterns
63//!
64//! ## Error Handling
65//!
66//! Wynd provides comprehensive error handling through the `WyndError` type and
67//! error event handlers. All async operations return `Result` types for proper
68//! error handling.
69//!
70//! ## Performance
71//!
72//! Wynd is built on Tokio's async runtime and Tungstenite's WebSocket implementation,
73//! providing excellent performance for high-concurrency WebSocket applications.
74//!
75//! ## License
76//!
77//! MIT License - see LICENSE file for details.
78
79/// WebSocket connection management and event handling.
80///
81/// This module provides the core connection types and event handling mechanisms
82/// for managing individual WebSocket connections.
83pub mod conn;
84
85/// Internal test utilities and integration tests.
86mod tests;
87
88/// Event types and error definitions.
89///
90/// This module contains all the event types used throughout the library,
91/// including message events, close events, and error types.
92pub mod types;
93
94/// Main WebSocket server implementation.
95///
96/// This module contains the `Wynd` struct and related server functionality
97/// for creating and managing WebSocket servers.
98pub mod wynd;