Expand description
Tools for spawning an accept loop that routes incoming requests to the right protocol.
§Example
let endpoint = Endpoint::bind().await?;
let router = Router::builder(endpoint).accept(b"/my/alpn", Echo).spawn();
// The protocol definition:
#[derive(Debug, Clone)]
struct Echo;
impl ProtocolHandler for Echo {
async fn accept(&self, connection: Connection) -> Result<(), AcceptError> {
let (mut send, mut recv) = connection.accept_bi().await?;
// Echo any bytes received back directly.
let bytes_sent = tokio::io::copy(&mut recv, &mut send).await?;
send.finish()?;
connection.closed().await;
Ok(())
}
}Structs§
- Access
Limit - Wraps an existing protocol, limiting its access, based on the provided function.
- Router
- The built router.
- Router
Builder - Builder for creating a
Routerfor accepting protocols.
Enums§
Traits§
- DynProtocol
Handler - A dyn-compatible version of
ProtocolHandlerthat returns boxed futures. - Protocol
Handler - Handler for incoming connections.