Struct wookie::Local [−][src]
pub struct Local<F> { /* fields omitted */ }
Expand description
An allocator-less single-future stepping executor for test suites that tracks wakers.
Unlike Wookie
, does not require a global allocator at the cost
of unsafe polling.
Examples
use core::task::Poll;
use wookie::local;
local!(future: async { true });
assert_eq!(unsafe { future.poll() }, Poll::Ready(true));
// you can also just give a variable name if you have one:
let future = async { true };
local!(future);
assert_eq!(unsafe { future.poll() }, Poll::Ready(true));
// we can find out about the state of wakers any time:
assert_eq!(future.cloned(), 0);
assert_eq!(future.dropped(), 0);
assert_eq!(future.woken(), 0);
// or equivalently...
future.stats().assert(0, 0, 0);
Implementations
Returns how many times the waker has been woken. This count is cumulative, it is never reset and is allowed to overflow.
Returns how many times the waker has been cloned. This count is cumulative, it is never reset and is allowed to overflow.
Returns how many times a clone of the waker has been dropped. This count is cumulative, it is never reset and is allowed to overflow.
Returns how many times a clone of the waker has been dropped. This count is cumulative, it is never reset and is allowed to overflow.
Polls the contained future to completion, so long as the previous poll caused one or more wakes.
Example
use core::task::Poll;
use wookie::local;
local!(future: async { true });
assert_eq!(unsafe { future.poll_while_woken() }, Poll::Ready(true));
Safety
You must not allow the Waker the future is polled with to
exist longer than self
.