pub trait Connected {
    type ConnectInfo: Clone + Send + Sync + 'static;

    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

The connection info type the IO resources generates.

Required Methods

Create type holding information about the connection.

Implementations on Foreign Types

Implementors