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.
Implementations on Foreign Types§
Source§impl Connected for AddrStream
impl Connected for AddrStream
type ConnectInfo = TcpConnectInfo
fn connect_info(&self) -> Self::ConnectInfo
Source§impl Connected for DuplexStream
impl Connected for DuplexStream
type ConnectInfo = ()
fn connect_info(&self) -> Self::ConnectInfo
Source§impl Connected for TcpStream
impl Connected for TcpStream
type ConnectInfo = TcpConnectInfo
fn connect_info(&self) -> Self::ConnectInfo
Source§impl<T> Connected for TlsStream<T>where
T: Connected,
Available on crate feature tls only.
impl<T> Connected for TlsStream<T>where
T: Connected,
Available on crate feature
tls only.