15 releases
0.6.6 | May 30, 2024 |
---|---|
0.6.4 | Feb 13, 2024 |
0.6.0 | Dec 24, 2023 |
0.5.2 | Apr 21, 2023 |
0.2.0 | Jul 26, 2021 |
#17 in #trillium
24 downloads per month
Used in 3 crates
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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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