Trait Local

Source
pub trait Local: Resource + Sized {
    type Remote: Remote;

    // Required methods
    fn listen_with(
        config: TransportListen,
        addr: SocketAddr,
    ) -> Result<ListeningInfo<Self>>;
    fn accept(&self, accept_remote: impl FnMut(AcceptedType<'_, Self::Remote>));

    // Provided method
    fn send_to(&self, _addr: SocketAddr, _data: &[u8]) -> SendStatus { ... }
}
Expand description

The resource used to represent a local listener. It usually is a wrapper over a socket/listener.

Required Associated Types§

Source

type Remote: Remote

The type of the Remote accepted by the Self::accept() function. It must be the same as the adapter’s Remote.

Required Methods§

Source

fn listen_with( config: TransportListen, addr: SocketAddr, ) -> Result<ListeningInfo<Self>>

Called when the user performs a listening request from an specific address. The implementator is in change of creating the corresponding local resource. It also must returned the listening address since it could not be the same as param addr (e.g. listening from port 0). The TransportListen wraps custom transport options for transports that support it. It is guaranteed by the upper level to be of the variant matching the adapter. Therefore other variants can be safely ignored.

Source

fn accept(&self, accept_remote: impl FnMut(AcceptedType<'_, Self::Remote>))

Called when a local resource received an event. It means that some resource have tried to connect. The implementator is in charge of accepting this connection. The accept_remote must be called for each accept request in the local resource. Note that an accept event could imply to process more than one remote. This function is called when the local resource has one or more pending connections. The implementator must process all these pending connections in this call. For most of the cases it means accept connections until the network resource returns WouldBlock.

Provided Methods§

Source

fn send_to(&self, _addr: SocketAddr, _data: &[u8]) -> SendStatus

Sends a raw data from a resource. Similar to Remote::send() but the resource that sends the data is a Local. This behaviour usually happens when the transport to implement is not connection oriented.

The implementator must only implement this function if the local resource can also send data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§