Struct aldrin::UnclaimedSender

source ·
pub struct UnclaimedSender<T: Serialize + ?Sized> { /* private fields */ }
Expand description

A sender that hasn’t been claimed yet.

UnclaimedSenders are similar to UnboundSenders in that they identify the sending end of a channel in an unclaimed state. This sender is however bound to a client and can thus be claimed.

Implementations§

source§

impl<T: Serialize + ?Sized> UnclaimedSender<T>

source

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

Unbinds the sender 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 sender) to another client, it must first be unbound from its client.

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

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

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

Closes the sender without consuming it.

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

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

§Examples
use aldrin::Error;

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

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

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

pub async fn claim(self) -> Result<Sender<T>, Error>

Claims the sender 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 sender, must be claimed manually (after it has possibly been sent to another client).

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

This function can fail in the following cases:

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

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

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

// This will now resolve immediately.
let mut receiver = receiver.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: Serialize + ?Sized>(self) -> UnclaimedSender<U>

Casts the item type to a different type.

Trait Implementations§

source§

impl<T: Debug + Serialize + ?Sized> Debug for UnclaimedSender<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T: ?Sized> Freeze for UnclaimedSender<T>

§

impl<T> !RefUnwindSafe for UnclaimedSender<T>

§

impl<T: ?Sized> Send for UnclaimedSender<T>

§

impl<T: ?Sized> Sync for UnclaimedSender<T>

§

impl<T: ?Sized> Unpin for UnclaimedSender<T>

§

impl<T> !UnwindSafe for UnclaimedSender<T>

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.