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

Creates a new Local without pinning it to the stack. You probably want the local! macro.

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 statistics about use of our wakers.

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 once.

Example

use core::task::Poll;
use wookie::local;
local!(future: async { true });
assert_eq!(unsafe { future.poll() }, Poll::Ready(true));

Safety

You must not allow the Waker the future is polled with to exist longer than self.

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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.