Trait LocalEndpointExt

Source
pub trait LocalEndpointExt: LocalEndpoint {
    // Provided methods
    fn send_as_stream<'a, S, R, SD>(
        &'a self,
        dest: S,
        send_desc: SD,
    ) -> SendAsStream<'a, R>
       where S: ToSocketAddrs<SocketAddr = Self::SocketAddr, Error = Self::SocketError> + 'a,
             SD: SendDesc<Self::InboundContext, R> + 'a,
             R: Send + 'a { ... }
    fn receive_as_stream<'a, F>(
        &'a self,
        handler: F,
    ) -> ReceiveAsStream<'a, Self, F>
       where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Unpin + Send { ... }
    fn receive_loop<'a, F>(
        &'a self,
        handler: F,
    ) -> Collect<ReceiveAsStream<'a, Self, F>, Error>
       where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Unpin + Send { ... }
    fn receive_loop_arc<'a, F>(
        self: Arc<Self>,
        handler: F,
    ) -> ArcGuard<Self, Collect<ReceiveAsStream<'a, Self, F>, Error>> 
       where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Send + Unpin,
             Self: 'a { ... }
}
Expand description

Extension trait for LocalEndpoint which implements additional helper methods.

Provided Methods§

Source

fn send_as_stream<'a, S, R, SD>( &'a self, dest: S, send_desc: SD, ) -> SendAsStream<'a, R>
where S: ToSocketAddrs<SocketAddr = Self::SocketAddr, Error = Self::SocketError> + 'a, SD: SendDesc<Self::InboundContext, R> + 'a, R: Send + 'a,

Sends a message where multiple responses are expected, returned as a SendAsStream.

In this version of LocalEndpoint::send, the send_desc can return ResponseStatus::Done from its handler multiple times, with the results being emitted from the returned SendAsStream.

The stream can be cleanly ended by the handler eventually returning Error::ResponseTimeout or Error::Cancelled, neither of which will be emitted as an error.

Source

fn receive_as_stream<'a, F>( &'a self, handler: F, ) -> ReceiveAsStream<'a, Self, F>
where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Unpin + Send,

Version of LocalEndpoint::receive that handles more than one inbound message, returning a crate::ReceiveAsStream instead of a future.

This stream will terminate immediately after any of the following errors are emitted by the underlying calls to LocalEndpoint::receive:

All other errors are ignored.

Source

fn receive_loop<'a, F>( &'a self, handler: F, ) -> Collect<ReceiveAsStream<'a, Self, F>, Error>
where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Unpin + Send,

Convenience method for implementing a receive loop.

The returned future will terminate when the underlying crate::ReceiveAsStream terminates, returning the error that was emitted before the stream terminated, typically either Error::IOError or Error::Cancelled.

Source

fn receive_loop_arc<'a, F>( self: Arc<Self>, handler: F, ) -> ArcGuard<Self, Collect<ReceiveAsStream<'a, Self, F>, Error>>
where F: FnMut(&Self::RespondableInboundContext) -> Result<(), Error> + 'a + Clone + Send + Unpin, Self: 'a,

Version of LocalEndpointExt::receive_loop which consumes and holds an Arc<Self>.

LocalEndpoints are often held inside of an [Arc<>], which makes using methods like LocalEndpointExt::receive_loop particularly awkward.

receive_loop_arc makes this situation relatively painless by returning the receive loop future in an (effectively transparent) ArcGuard wrapper.


let local_endpoint = Arc::new(NullLocalEndpoint);
let mut pool = ThreadPool::new().expect("Unable to start thread pool");

pool.spawn(local_endpoint
    .clone()
    .receive_loop_arc(null_receiver!())
    .map(|err| panic!("Receive loop terminated: {}", err))
);

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§

Source§

impl<T: LocalEndpoint> LocalEndpointExt for T

Blanket implementation of LocalEndpointExt for all LocalEndpoint instances.