pub struct ConvertingCallbackReceiver<T: FromByteSlice> { /* private fields */ }
Expand description
A wrapper for Receiver
, which converts received byte vectors to structured data. This variant of
ConvertingReceiver
is used for events.
This receiver wraps a Receiver
receiving raw bytes. Calling recv_forever
, recv_timeout
or try_recv
will call equivalent methods on the wrapped Receiver
and then convert the received bytes
to a instance of T
.
§Type parameters
T
- Type which is created from received byte vectors. Must implementFromByteSlice
§Errors
Returned errors are equivalent to those returned from methods of a Receiver
.
If the received response can not be interpreted as the result type T
, a MalformedPacket
error is raised.
Implementations§
source§impl<T: FromByteSlice> ConvertingCallbackReceiver<T>
impl<T: FromByteSlice> ConvertingCallbackReceiver<T>
sourcepub fn new(receiver: Receiver<Vec<u8>>) -> ConvertingCallbackReceiver<T>
pub fn new(receiver: Receiver<Vec<u8>>) -> ConvertingCallbackReceiver<T>
Creates a new converting callback receiver which wraps the given Receiver
.
sourcepub fn try_recv(&self) -> Result<T, CallbackTryRecvError>
pub fn try_recv(&self) -> Result<T, CallbackTryRecvError>
sourcepub fn recv_forever(&self) -> Result<T, CallbackRecvError>
pub fn recv_forever(&self) -> Result<T, CallbackRecvError>
sourcepub fn recv_timeout(
&self,
timeout: Duration
) -> Result<T, CallbackRecvTimeoutError>
pub fn recv_timeout( &self, timeout: Duration ) -> Result<T, CallbackRecvTimeoutError>
Attempts to wait for a value on this receiver, returning an error if the corresponding channel has hung up, or if it waits more than timeout.
This method behaves like recv_timeout
.
§Errors
Returns an error on one of the following conditions:
- The queue was disconnected.
- The received packet was malformed.
- Blocked longer than the configured time out.