pub trait Connected {
type ConnectInfo: Clone + Send + Sync + 'static;
// Required method
fn connect_info(&self) -> Self::ConnectInfo;
}
Expand description
Trait that connected IO resources implement and use to produce info about the connection.
The goal for this trait is to allow users to implement custom IO types that can still provide the same connection metadata.
§Example
The ConnectInfo
returned will be accessible through request extensions:
use tonic::{Request, transport::server::Connected};
// A `Stream` that yields connections
struct MyConnector {}
// Return metadata about the connection as `MyConnectInfo`
impl Connected for MyConnector {
type ConnectInfo = MyConnectInfo;
fn connect_info(&self) -> Self::ConnectInfo {
MyConnectInfo {}
}
}
#[derive(Clone)]
struct MyConnectInfo {
// Metadata about your connection
}
// The connect info can be accessed through request extensions:
let connect_info: &MyConnectInfo = request
.extensions()
.get::<MyConnectInfo>()
.expect("bug in tonic");
Required Associated Types§
sourcetype ConnectInfo: Clone + Send + Sync + 'static
type ConnectInfo: Clone + Send + Sync + 'static
The connection info type the IO resources generates.
Required Methods§
sourcefn connect_info(&self) -> Self::ConnectInfo
fn connect_info(&self) -> Self::ConnectInfo
Create type holding information about the connection.