Trait tonic::transport::server::Connected

source ·
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§

source

type ConnectInfo: Clone + Send + Sync + 'static

The connection info type the IO resources generates.

Required Methods§

source

fn connect_info(&self) -> Self::ConnectInfo

Create type holding information about the connection.

Implementations on Foreign Types§

source§

impl Connected for AddrStream

source§

impl Connected for DuplexStream

source§

impl Connected for TcpStream

source§

impl Connected for UnixStream

Implementors§