Skip to main content

Borrowed

Struct Borrowed 

Source
pub struct Borrowed<'wait_list, I, O> { /* private fields */ }
Expand description

The borrowed contents of a WaitList.

For a given WaitList only one of these may exist at once.

Implementations§

Source§

impl<I, O> Borrowed<'_, I, O>

Source

pub fn is_empty(&self) -> bool

Check whether there are any futures waiting in this list.

Source

pub fn head_input(&self) -> Option<&I>

Retrieve a shared reference to the input given by the head entry in the list, if there is one.

Source

pub fn head_input_mut(&mut self) -> Option<&mut I>

Retrieve a unique reference to the input given by the head entry in the list, if there is one.

Source

pub fn wake_one(&mut self, output: O) -> Result<I, WakeOneError<O>>

Wake and dequeue the first waiter in the queue, if there is one.

Returns ownership of that waiter’s input value.

§Examples
use std::future::Future;
use std::task::Poll;

use unsync::wait_list::WaitList;

let list = WaitList::<u32, u32>::new();
let mut future = Box::pin(list.wait(5));
assert_eq!(future.as_mut().poll(cx), Poll::Pending);
assert_eq!(list.borrow().head_input(), Some(&5));

list.borrow().wake_one(6).unwrap();
assert_eq!(future.as_mut().poll(cx), Poll::Ready(6));
assert_eq!(list.borrow().head_input(), None);

Example waking multiple tasks:

use std::future::Future;
use std::task::Poll;

use unsync::wait_list::WaitList;

let list = WaitList::<u32, u32>::new();

let mut f1 = Box::pin(list.wait(1));
let mut f2 = Box::pin(list.wait(2));
let mut f3 = Box::pin(list.wait(3));

assert_eq!(f1.as_mut().poll(cx), Poll::Pending);
assert_eq!(f2.as_mut().poll(cx), Poll::Pending);

assert!(list.borrow().wake_one(1).is_ok());
assert_eq!(f3.as_mut().poll(cx), Poll::Pending);

assert!(list.borrow().wake_one(2).is_ok());
assert!(list.borrow().wake_one(3).is_ok());

assert_eq!(f1.as_mut().poll(cx), Poll::Ready(1));
assert_eq!(f2.as_mut().poll(cx), Poll::Ready(2));
assert_eq!(f3.as_mut().poll(cx), Poll::Ready(3));
§Errors

Returns an error when there are no wakers in the list.

use unsync::wait_list::WaitList;

let list = WaitList::<(), ()>::new();
list.borrow().wake_one(()).unwrap_err();
assert_eq!(list.borrow().head_input(), None);

Trait Implementations§

Source§

impl<'wait_list, I: Debug, O: Debug> Debug for Borrowed<'wait_list, I, O>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<I, O> Drop for Borrowed<'_, I, O>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'wait_list, I, O> !RefUnwindSafe for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> !Send for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> !Sync for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> !UnwindSafe for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> Freeze for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> Unpin for Borrowed<'wait_list, I, O>

§

impl<'wait_list, I, O> UnsafeUnpin for Borrowed<'wait_list, I, O>

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>,

Source§

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>,

Source§

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.