Struct aldrin::UnboundReceiver
source · pub struct UnboundReceiver<T> { /* 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> UnboundReceiver<T>
impl<T> UnboundReceiver<T>
sourcepub fn new(cookie: ChannelCookie) -> Self
pub fn new(cookie: ChannelCookie) -> Self
Creates a new UnboundReceiver
from a ChannelCookie
.
Returns the receiver’s ChannelCookie
.
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>(self) -> UnboundReceiver<U>
pub fn cast<U>(self) -> UnboundReceiver<U>
Casts the item type to a different type.
Trait Implementations§
source§impl<T> Clone for UnboundReceiver<T>
impl<T> Clone for UnboundReceiver<T>
source§impl<T> Debug for UnboundReceiver<T>
impl<T> Debug for UnboundReceiver<T>
source§impl<T> Deserialize for UnboundReceiver<T>
impl<T> Deserialize for UnboundReceiver<T>
fn deserialize( deserializer: Deserializer<'_, '_>, ) -> Result<Self, DeserializeError>
source§impl<T1, T2> PartialEq<UnboundReceiver<T2>> for UnboundReceiver<T1>
impl<T1, T2> PartialEq<UnboundReceiver<T2>> for UnboundReceiver<T1>
source§impl<T> Serialize for UnboundReceiver<T>
impl<T> Serialize for UnboundReceiver<T>
fn serialize(&self, serializer: Serializer<'_>) -> Result<(), SerializeError>
impl<T> Copy for UnboundReceiver<T>
impl<T> Eq for UnboundReceiver<T>
Auto Trait Implementations§
impl<T> Freeze for UnboundReceiver<T>
impl<T> RefUnwindSafe for UnboundReceiver<T>
impl<T> Send for UnboundReceiver<T>
impl<T> Sync for UnboundReceiver<T>
impl<T> Unpin for UnboundReceiver<T>
impl<T> UnwindSafe for UnboundReceiver<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)