14 releases

0.6.5 Apr 7, 2024
0.6.4 Feb 13, 2024
0.6.3 Jan 22, 2024
0.6.0 Dec 24, 2023
0.2.0 Jul 26, 2021

#12 in #trillium

Download history 68/week @ 2023-12-22 225/week @ 2023-12-29 132/week @ 2024-01-05 39/week @ 2024-01-19 43/week @ 2024-02-09 22/week @ 2024-02-16 48/week @ 2024-02-23 30/week @ 2024-03-01 10/week @ 2024-03-08 9/week @ 2024-03-15 17/week @ 2024-03-22 47/week @ 2024-03-29 158/week @ 2024-04-05

231 downloads per month
Used in 3 crates

MIT/Apache

345KB
6.5K SLoC

Welcome to Trillium!

📖 Guide 📖

The guide provides an architectural overview and lay of the land connecting the trillium crates.

📑 Rustdocs 📑

The rustdocs represent the best way to learn about any of trillium's individual crates and the specific interfaces.




Legal:

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

A websocket trillium handler

There are three primary ways to use this crate

With an async function that receives a WebSocketConn

This is the simplest way to use trillium websockets, but does not provide any of the affordances that implementing the WebSocketHandler trait does. It is best for very simple websockets or for usages that require moving the WebSocketConn elsewhere in an application. The WebSocketConn is fully owned at this point, and will disconnect when dropped, not when the async function passed to websocket completes.

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

let handler = websocket(|mut conn: WebSocketConn| async move {
while let Some(Ok(Message::Text(input))) = conn.next().await {
conn.send_string(format!("received your message: {}", &input)).await;
}
});

Implementing WebSocketHandler

WebSocketHandler provides support for sending outbound messages as a stream, and simplifies common patterns like executing async code on received messages.

Using JsonWebSocketHandler

JsonWebSocketHandler provides a thin serialization and deserialization layer on top of WebSocketHandler for this common use case. See the JsonWebSocketHandler documentation for example usage. In order to use this trait, the json cargo feature must be enabled.

Dependencies

~9.5MB
~228K SLoC