ServiceRouter

Trait ServiceRouter 

Source
pub trait ServiceRouter: Send + Sync {
    type Error: Error + Send + Sync + 'static;
    type ServiceId: Debug + Send + Sync;
    type Service: Service;

    // Required methods
    fn parse_service_id<'life0, 'async_trait>(
        &'life0 self,
        service_id: u8,
    ) -> Pin<Box<dyn Future<Output = Result<Self::ServiceId, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn create_service<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        service_id: &'life1 Self::ServiceId,
        connection_info: &'life2 ConnectionInfo,
        streams: StreamPair,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Service, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Routes incoming connections to appropriate services

The router is responsible for parsing service identifiers and creating service instances to handle connections.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The error type returned by routing operations

Source

type ServiceId: Debug + Send + Sync

The typed service identifier (e.g., an enum)

Source

type Service: Service

The service type that handles connections

Required Methods§

Source

fn parse_service_id<'life0, 'async_trait>( &'life0 self, service_id: u8, ) -> Pin<Box<dyn Future<Output = Result<Self::ServiceId, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Parse a raw service ID byte into a typed service identifier

§Arguments
  • service_id - The raw service ID byte sent by the client
§Returns

A typed service identifier or an error if the ID is invalid

Source

fn create_service<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, service_id: &'life1 Self::ServiceId, connection_info: &'life2 ConnectionInfo, streams: StreamPair, ) -> Pin<Box<dyn Future<Output = Result<Self::Service, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a service instance for the given service ID

§Arguments
  • service_id - The parsed service identifier
  • connection_info - Information about the authenticated client
  • streams - The bi-directional streams for communication
§Returns

A service instance ready to handle the connection

Implementors§