pub struct UnclaimedReceiver<T: Deserialize> { /* private fields */ }
Expand description

A receiver that hasn’t been claimed yet.

UnclaimedReceivers are similar to UnboundReceivers in that they identify the receiving end of a channel in an unclaimed state. This receiver is however bound to a client and can thus be claimed.

Implementations§

source§

impl<T: Deserialize> UnclaimedReceiver<T>

source

pub fn unbind(self) -> UnboundReceiver<T>

Unbinds the receiver from its client.

When creating a channel, one end will already be claimed while the other end won’t. In order to send that other end (here the receiver) to another client, it must first be unbound from its client.

§Examples
// Create a channel with an unclaimed receiver and a claimed sender.
let (sender, receiver) = handle.create_channel_with_claimed_sender::<u32>().await?;

// Unbind the receiver so that it can be sent to another client. This will typically happen
// by returning it from a function call.
let receiver = receiver.unbind();
source

pub async fn close(&mut self) -> Result<(), Error>

Closes the receiver without consuming it.

This closes the receiver such that it cannot be claimed anymore by any client. When the sender waits for the channel to become established, an error will be returned.

After closing a receiver, any further function calls will return Error::InvalidChannel.

§Examples
use aldrin::Error;

let (sender, mut receiver) = handle.create_channel_with_claimed_sender::<u32>().await?;

// Close the receiver.
receiver.close().await?;

// For the sender, an error will be returned when waiting for the channel to become
// established.
let err = sender.established().await.unwrap_err();
assert_eq!(err, Error::InvalidChannel);
source

pub async fn claim(self, capacity: u32) -> Result<Receiver<T>, Error>

Claims the receiver by its bound client.

When creating channels, both ends must be claimed by a client before items can be sent and received. One end will always be claimed automatically. The other end, here the receiver, must be claimed manually (after it has possibly been sent to another client).

When this function returns successfully, a senders’s call to PendingSender::established will also resolve successfully.

This function can fail in the following cases:

  • Some other client has already claimed the receiver.
  • Some other client has closed the receiver.
  • The sender has been closed.

A capacity of 0 is treated as if 1 was specificed instead.

§Examples

// The receiver is unclaimed, while the sender has been claimed automatically.
let (sender, receiver) = handle.create_channel_with_claimed_sender().await?;

// Claim the receiver.
let mut receiver = receiver.claim(16).await?;

// This will now resolve immediately.
let mut sender = sender.established().await?;

// The channel is now fully established and items can be sent and received.
sender.send_item(&1).await?;
sender.send_item(&2).await?;
assert_eq!(receiver.next_item().await, Ok(Some(1)));
assert_eq!(receiver.next_item().await, Ok(Some(2)));
source

pub fn cast<U: Deserialize>(self) -> UnclaimedReceiver<U>

Casts the item type to a different type.

Trait Implementations§

source§

impl<T: Debug + Deserialize> Debug for UnclaimedReceiver<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.