Expand description
§Wynd - A Simple WebSocket Library for Rust
Wynd is a lightweight, async WebSocket server library built on Tokio and Tungstenite, designed to provide an excellent developer experience for building WebSocket applications in Rust.
§Features
- Simple API: Easy-to-use event-driven API with async/await support
- Type Safety: Strongly typed message events and error handling
- High Performance: Built on Tokio for excellent async performance
- Connection Management: Automatic connection lifecycle management
- Error Handling: Comprehensive error handling with custom error types
§Quick Start
use wynd::wynd::{Wynd, Standalone};
#[tokio::main]
async fn main() {
let mut wynd: Wynd<Standalone> = Wynd::new();
wynd.on_connection(|conn| async move {
println!("New connection established: {}", conn.id());
conn.on_open(|handle| async move {
println!("Connection {} is now open", handle.id());
})
.await;
conn.on_text(|msg, handle| async move {
println!("Message received: {}", msg.data);
// Echo the message back
let _ = handle.send_text(&msg.data).await;
});
});
wynd
.listen(8080, || {
println!("Listening on port 8080");
})
.await
.unwrap();
}§Core Concepts
- Wynd: The main server instance that manages connections and handles server-level events
- Connection: Represents an individual WebSocket connection with event handlers
- ConnectionHandle: Provides methods to interact with a connection (send messages, close, etc.)
- Events: Typed events for different WebSocket message types (text, binary, close, error)
§Examples
See the examples/ directory for more comprehensive examples:
- Basic echo server
- Chat room implementation
- Binary data handling
- Error handling patterns
§Error Handling
Wynd provides comprehensive error handling through the WyndError type and
error event handlers. All async operations return Result types for proper
error handling.
§Performance
Wynd is built on Tokio’s async runtime and Tungstenite’s WebSocket implementation, providing excellent performance for high-concurrency WebSocket applications.
§License
MIT License - see LICENSE file for details.
Modules§
- conn
- WebSocket connection management and event handling.
- handle
- Connection handle utilities.
- room
- Room management and room event types.
- types
- Event types and error definitions.
- wynd
- Main WebSocket server implementation.
Structs§
- Middleware
- Middleware struct that wraps a middleware handler function.
- Next
- Represents the “next” middleware in the chain.