pub trait Handler: Send + Sync {
type Codec: Encoder<Bytes, Error = Error> + Decoder<Item = BytesMut, Error = Error> + Clone + Send + Sync + 'static + TfCodec;
// Required methods
fn serve_route<'life0, 'life1, 'async_trait>(
&'life0 mut self,
client_meta: (SocketAddr, &'life1 mut Option<Sender<Arc<Mutex<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§
type Codec: Encoder<Bytes, Error = Error> + Decoder<Item = BytesMut, Error = Error> + Clone + Send + Sync + 'static + TfCodec
Required Methods§
Sourcefn serve_route<'life0, 'life1, 'async_trait>(
&'life0 mut self,
client_meta: (SocketAddr, &'life1 mut Option<Sender<Arc<Mutex<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 serve_route<'life0, 'life1, 'async_trait>(
&'life0 mut self,
client_meta: (SocketAddr, &'life1 mut Option<Sender<Arc<Mutex<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.
Sourcefn 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,
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.