karyon_net::connection

Trait Connection

Source
pub trait Connection: Send + Sync {
    type Message;
    type Error;

    // Required methods
    fn peer_endpoint(&self) -> Result<Endpoint, Self::Error>;
    fn local_endpoint(&self) -> Result<Endpoint, Self::Error>;
    fn recv<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Message, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn send<'life0, 'async_trait>(
        &'life0 self,
        msg: Self::Message,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Connection is a generic network connection interface for [udp::UdpConn], [tcp::TcpConn], [tls::TlsConn], [ws::WsConn], and [unix::UnixConn].

If you are familiar with the Go language, this is similar to the Conn interface

Required Associated Types§

Required Methods§

Source

fn peer_endpoint(&self) -> Result<Endpoint, Self::Error>

Returns the remote peer endpoint of this connection

Source

fn local_endpoint(&self) -> Result<Endpoint, Self::Error>

Returns the local socket endpoint of this connection

Source

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

Recvs data from this connection.

Source

fn send<'life0, 'async_trait>( &'life0 self, msg: Self::Message, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends data to this connection

Implementors§

Source§

impl<C, E> Connection for TcpConn<C>
where C: Codec<Error = E> + Clone,

Source§

impl<C, E> Connection for TlsConn<C>
where C: Clone + Codec<Error = E>,

Source§

impl<C, E> Connection for UdpConn<C>
where C: Codec<Error = E> + Clone, E: From<Error>,

Source§

impl<C, E> Connection for UnixConn<C>
where C: Codec<Error = E> + Clone, E: From<Error>,

Source§

impl<C, E> Connection for WsConn<C>
where C: WebSocketCodec<Error = E>, E: From<Error>,