trillium-websockets 0.7.0

websocket support for trillium.rs
Documentation

🔌 trillium-websockets — WebSocket handler

ci crates.io version docs.rs

WebSocket handler for Trillium, built on async-tungstenite. Accepts WebSocket upgrade requests and hands each connection to an async handler function or a WebSocketHandler implementation. Optionally supports the json feature for typed JSON message handling via JsonWebSocketHandler.

Example

use futures_lite::stream::StreamExt;
use trillium_websockets::{Message, WebSocketConn, websocket};

let app = websocket(|mut conn: WebSocketConn| async move {
    while let Some(Ok(Message::Text(input))) = conn.next().await {
        conn.send_string(format!("received: {input}")).await;
    }
});
// run with your chosen runtime adapter, e.g.:
// trillium_tokio::run(app);

Safety

This crate uses #![forbid(unsafe_code)].

License