Skip to main content

Handler

Trait Handler 

Source
pub trait Handler: Send + Sync {
    type Codec: TfCodec;

    // Required methods
    fn serve_route<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        client_meta: (SocketAddr, &'life1 mut Option<Sender<Arc<RwLock<dyn Handler<Codec = Self::Codec>>>>>),
        s_type: Box<dyn StructureType>,
        data: BytesMut,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Vec<u8>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn accept_stream<'life0, 'async_trait>(
        &'life0 mut self,
        add: SocketAddr,
        stream: (Framed<Transport, Self::Codec>, TrafficProcessorHolder<Self::Codec>),
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The server handler trait. Used for handling data from client/

Required Associated Types§

Required Methods§

Source

fn serve_route<'life0, 'life1, 'async_trait>( &'life0 mut self, client_meta: (SocketAddr, &'life1 mut Option<Sender<Arc<RwLock<dyn Handler<Codec = Self::Codec>>>>>), s_type: Box<dyn StructureType>, data: BytesMut, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The serve_route called by router, when the new data arrived and designated to registered to this handler structure_types.

‘client_meta’ is client info, and signal for requesting to move stream. If request needed, call take() on this option ‘’’if let Some(tx) = meta.1.take(){ ‘’’ tx.send(…).unwrap(); ‘’’} ‘s_type’ is identified request structure type ‘data’ is binary representation of the structure. Call the deserialize from s_type to turn it into base structure.

Source

fn accept_stream<'life0, 'async_trait>( &'life0 mut self, add: SocketAddr, stream: (Framed<Transport, Self::Codec>, TrafficProcessorHolder<Self::Codec>), ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

This function called, when server received the request of handler to move stream. It returns all needed data for this stream.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§