[−][src]Trait async_coap::LocalEndpointExt
Extension trait for LocalEndpoint
which implements additional helper methods.
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,
&'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.
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,
&'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.
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,
&'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
.
ⓘImportant traits for ArcGuard<RC, T>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,
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>
].
LocalEndpoint
s 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)) );
Implementors
impl<T: LocalEndpoint> LocalEndpointExt for T
[src]
Blanket implementation of LocalEndpointExt
for all LocalEndpoint
instances.