Struct aldrin::UnboundReceiver
source · pub struct UnboundReceiver<T: Deserialize> { /* private fields */ }
Expand description
A receiver that is not bound to any particular client.
UnboundReceiver
s are used to transfer receivers to some other client, typically by
returning them from function calls.
When creating a channel the resulting
UnclaimedReceiver
can be unbound and sent to another client.
It is worth noting that this type implements Copy
and Clone
. As such (and because it is
not bound to any client), it will not close the receiving end of a channel. This is the main
difference from UnclaimedReceiver
.
Implementations§
source§impl<T: Deserialize> UnboundReceiver<T>
impl<T: Deserialize> UnboundReceiver<T>
sourcepub fn bind(self, client: Handle) -> UnclaimedReceiver<T>
pub fn bind(self, client: Handle) -> UnclaimedReceiver<T>
Binds the receiver to a client.
See also claim
to bind and claim the receiver in one step.
§Examples
use aldrin::{Receiver, UnclaimedReceiver};
// Assume this receiver has been returned from some function call.
// let receiver: UnboundReceiver<u32> = ...
// Bind it to the local client. The explicit type is shown here only for the sake of the
// example.
let receiver: UnclaimedReceiver<u32> = receiver.bind(handle.clone());
// Afterwards, it can be claimed.
let receiver: Receiver<u32> = receiver.claim(16).await?;
sourcepub async fn claim(
self,
client: Handle,
capacity: u32
) -> Result<Receiver<T>, Error>
pub async fn claim( self, client: Handle, capacity: u32 ) -> Result<Receiver<T>, Error>
Binds the receiver to a client and claims it.
This function is equivalent to receiver.bind(client).claim()
.
See UnclaimedReceiver::claim
for explanation of the cases in which this function can
fail.
A capacity
of 0 is treated as if 1 was specificed instead.
§Examples
use aldrin::Receiver;
// Assume this receiver has been returned from some function call.
// let receiver: UnboundReceiver<u32> = ...
// Bind it to the local client and claim it, so that it can immediately be used. The
// explicit type here is given only for the sake of the example.
let receiver: Receiver<u32> = receiver.claim(handle.clone(), 16).await?;
sourcepub fn cast<U: Deserialize>(self) -> UnboundReceiver<U>
pub fn cast<U: Deserialize>(self) -> UnboundReceiver<U>
Casts the item type to a different type.
Trait Implementations§
source§impl<T: Clone + Deserialize> Clone for UnboundReceiver<T>
impl<T: Clone + Deserialize> Clone for UnboundReceiver<T>
source§fn clone(&self) -> UnboundReceiver<T>
fn clone(&self) -> UnboundReceiver<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug + Deserialize> Debug for UnboundReceiver<T>
impl<T: Debug + Deserialize> Debug for UnboundReceiver<T>
source§impl<T: Deserialize> Deserialize for UnboundReceiver<T>
impl<T: Deserialize> Deserialize for UnboundReceiver<T>
fn deserialize( deserializer: Deserializer<'_, '_> ) -> Result<Self, DeserializeError>
source§impl<T: PartialEq + Deserialize> PartialEq for UnboundReceiver<T>
impl<T: PartialEq + Deserialize> PartialEq for UnboundReceiver<T>
source§fn eq(&self, other: &UnboundReceiver<T>) -> bool
fn eq(&self, other: &UnboundReceiver<T>) -> bool
self
and other
values to be equal, and is used
by ==
.