roa-websocket-0.5.0-rc doesn't have any documentation.
Roa-websocket
This crate provides a websocket endpoint.
Example
use StreamExt;
use ;
use Websocket;
use ;
use Method;
#
This crate provides a websocket endpoint.
use futures::StreamExt;
use roa_router::{Router, RouterError};
use roa_websocket::Websocket;
use roa_core::{App, SyncContext};
use roa_core::http::Method;
# fn main() -> Result<(), RouterError> {
let mut app = App::new(());
let mut router = Router::new();
router.end(
"/chat",
[Method::GET],
Websocket::new(|_ctx: SyncContext<()>, stream| async move {
let (write, read) = stream.split();
// echo
if let Err(err) = read.forward(write).await {
println!("forward err: {}", err);
}
}),
);
app.gate(router.routes("/")?);
Ok(())
# }