Trait Remote

Source
pub trait Remote: Resource + Sized {
    // Required methods
    fn connect_with(
        config: TransportConnect,
        remote_addr: RemoteAddr,
    ) -> Result<ConnectionInfo<Self>>;
    fn receive(&self, process_data: impl FnMut(&[u8])) -> ReadStatus;
    fn send(&self, data: &[u8]) -> SendStatus;
    fn pending(&self, readiness: Readiness) -> PendingStatus;

    // Provided method
    fn ready_to_write(&self) -> bool { ... }
}
Expand description

The resource used to represent a remote. It usually is a wrapper over a socket/stream.

Required Methods§

Source

fn connect_with( config: TransportConnect, remote_addr: RemoteAddr, ) -> Result<ConnectionInfo<Self>>

Called when the user performs a connection request to an specific remote address. The implementator is in change of creating the corresponding remote resource. The TransportConnect 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. The RemoteAddr contains either a SocketAddr or a url::Url. It is in charge of deciding what to do in both cases. It also must return the extracted address as SocketAddr.

Source

fn receive(&self, process_data: impl FnMut(&[u8])) -> ReadStatus

Called when a remote resource received an event. The resource must be ready to receive this call. It means that it has available data to read, or there is some connection related issue, as a disconnection. The implementator is in charge of processing that action and returns a ReadStatus.

The process_data function must be called for each data chunk that represents a message. This call will produce a crate::network::NetEvent::Message API event. Note that receive() could imply more than one call to read. The implementator must be read all data from the resource. For most of the cases it means read until the network resource returns WouldBlock.

Source

fn send(&self, data: &[u8]) -> SendStatus

Sends raw data from a resource. The resource must be ready to receive this call. The implementator is in charge to send the entire data. The SendStatus will contain the status of this attempt.

Source

fn pending(&self, readiness: Readiness) -> PendingStatus

Called when a Remote is created (explicity of by a listener) and it is not consider ready yet. A remote resource is considered ready when it is totally connected and can be used for writing data. It implies that the user has received the Connected or Accepted method for that resource.

This method is in charge to determine if a resource is ready or not. No Connected or Accepted events will be generated until this function return PendingStatus::Ready. The method wil be called several times with different Readiness until the implementator returns a PendingStatus::Ready or PendingStatus::Disconnected.

Provided Methods§

Source

fn ready_to_write(&self) -> bool

The resource is available to write. It must be ready to receive this call. Here the implementator optionally can try to write any pending data. The return value is an identification of the operation result. If the method returns true, the operation was successful, otherwise, the resource will be disconnected and removed.

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§