Trait ServiceProtocol

Source
pub trait ServiceProtocol: Send {
    // Required method
    fn init<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        context: &'life1 mut ProtocolContext,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn connected<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _context: ProtocolContextMutRef<'life1>,
        _version: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait { ... }
    fn disconnected<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: ProtocolContextMutRef<'life1>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn received<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: ProtocolContextMutRef<'life1>,
        _data: Bytes,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn notify<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut ProtocolContext,
        _token: u64,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn poll<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut ProtocolContext,
    ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Service level protocol handle

§Note

All functions on this trait will block the entire server running, do not insert long-time tasks, you can use the futures task instead.

§Behavior

Define the behavior of each custom protocol in each state.

Depending on whether the user defines a service handle or a session exclusive handle, the runtime has different performance.

The important difference is that some state values are allowed in the service handle, and the handle exclusive to the session is “stateless”, relative to the service handle, it can only retain the information between a protocol stream on and off.

The opening and closing of the protocol will create and clean up the handle exclusive to the session, but the service handle will remain in the state until the service is closed.

Required Methods§

Source

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

This function is called when the service start.

The service handle will only be called once

Provided Methods§

Source

fn connected<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _context: ProtocolContextMutRef<'life1>, _version: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Called when opening protocol

Source

fn disconnected<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: ProtocolContextMutRef<'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Called when closing protocol

Source

fn received<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: ProtocolContextMutRef<'life1>, _data: Bytes, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Called when the corresponding protocol message is received

Source

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 mut ProtocolContext, _token: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Called when the Service receives the notify task

Source

fn poll<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Behave like Stream::poll_next, but nothing output if ready with Some, it will continue poll immediately if ready with None, it will don’t try to call the function again

Trait Implementations§

Source§

impl ServiceProtocol for Box<dyn ServiceProtocol + Unpin + Send + Sync>

Source§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

This function is called when the service start. Read more
Source§

fn connected<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Called when opening protocol
Source§

fn disconnected<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Called when closing protocol
Source§

fn received<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, data: Bytes, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Called when the corresponding protocol message is received
Source§

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, token: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Called when the Service receives the notify task
Source§

fn poll<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Behave like Stream::poll_next, but nothing output if ready with Some, it will continue poll immediately if ready with None, it will don’t try to call the function again
Source§

impl ServiceProtocol for Box<dyn ServiceProtocol + Unpin + Send>

Source§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

This function is called when the service start. Read more
Source§

fn connected<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Called when opening protocol
Source§

fn disconnected<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Called when closing protocol
Source§

fn received<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, data: Bytes, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Called when the corresponding protocol message is received
Source§

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, token: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Called when the Service receives the notify task
Source§

fn poll<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Behave like Stream::poll_next, but nothing output if ready with Some, it will continue poll immediately if ready with None, it will don’t try to call the function again

Implementations on Foreign Types§

Source§

impl ServiceProtocol for Box<dyn ServiceProtocol + Unpin + Send + Sync>

Source§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

fn connected<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

fn disconnected<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

fn received<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, data: Bytes, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, token: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

fn poll<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send + Sync>: 'async_trait,

Source§

impl ServiceProtocol for Box<dyn ServiceProtocol + Unpin + Send>

Source§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Source§

fn connected<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Source§

fn disconnected<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Source§

fn received<'life0, 'life1, 'async_trait>( &'life0 mut self, context: ProtocolContextMutRef<'life1>, data: Bytes, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Source§

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, token: u64, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Source§

fn poll<'life0, 'life1, 'async_trait>( &'life0 mut self, context: &'life1 mut ProtocolContext, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn ServiceProtocol + Unpin + Send>: 'async_trait,

Implementors§