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>
impl<I, O> Borrowed<'_, I, O>
Sourcepub fn head_input(&self) -> Option<&I>
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.
Sourcepub fn head_input_mut(&mut self) -> Option<&mut I>
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.
Sourcepub fn wake_one(&mut self, output: O) -> Result<I, WakeOneError<O>>
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§
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> 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
Mutably borrows from an owned value. Read more