pub struct Weak<T> { /* private fields */ }Expand description
A weak reference to a Producer/Consumer state.
Does not affect ref counts, so it won’t prevent auto-close when all Producers are dropped. Can be upgraded to a full Producer or Consumer.
Implementations§
Source§impl<T> Weak<T>
impl<T> Weak<T>
Sourcepub fn produce(&self) -> Option<Producer<T>>
pub fn produce(&self) -> Option<Producer<T>>
Upgrade to a Producer, returning None if the channel is already closed.
Sourcepub fn write(&self) -> Result<Mut<'_, T>, Ref<'_, T>>
pub fn write(&self) -> Result<Mut<'_, T>, Ref<'_, T>>
Acquire mutable access to the shared state without upgrading to a full Producer.
Returns Ok(Mut) if the channel is open, or Err(Ref) with
read-only access if closed. Only locks once.
Sourcepub fn poll_write<F, R>(&self, waiter: &Waiter, f: F) -> Poll<Option<R>>
pub fn poll_write<F, R>(&self, waiter: &Waiter, f: F) -> Poll<Option<R>>
Poll-based mutable access with waker registration.
Calls f with a Mut guard. If f returns Poll::Pending,
registers the waiter for notification when the state next changes.
Returns None if the channel is closed.
Sourcepub async fn wait<F, R>(&self, f: F) -> Result<R, Ref<'_, T>>
pub async fn wait<F, R>(&self, f: F) -> Result<R, Ref<'_, T>>
Wait for the closure to return Poll::Ready, re-polling on each state change.
Returns Ok(R) when the closure returns Poll::Ready, or Err(Ref) with
read-only access to the final state if the channel closes first.
Sourcepub async fn unused(&self) -> Result<(), Ref<'_, T>>
pub async fn unused(&self) -> Result<(), Ref<'_, T>>
Wait until all consumers have been dropped.
Returns Ok(()) when no consumers remain, or Err(Ref) if the channel closes first.
Sourcepub fn same_channel(&self, other: &Self) -> bool
pub fn same_channel(&self, other: &Self) -> bool
Returns true if both weak references share the same underlying state.