Skip to main content

Driver

Trait Driver 

Source
pub trait Driver<'a> {
    // Required method
    fn poll(
        self: Pin<&mut Self>,
        args: &mut Unstructured<'a>,
    ) -> Result<Poll<ControlFlow<()>>>;
}
Expand description

The other side of the leaf future under test, responsible for making it progress.

For example:

  • if the leaf future is the receiver of a channel, the driver is the sender.
  • if the leaf future is a timeout, the driver is the timer system.

See drive_poll_fn, drive_fn, and drive_sink for convenient constructors.

Required Methods§

Source

fn poll( self: Pin<&mut Self>, args: &mut Unstructured<'a>, ) -> Result<Poll<ControlFlow<()>>>

Drive the leaf future to make progress.

Key invariant: when this returns Poll::Ready, the framework asserts that the future’s waker was called. Return Poll::Pending if no progress was made (e.g. the channel is full) to skip that assertion.

  • Poll::Ready(ControlFlow::Continue(())) – progress made
  • Poll::Ready(ControlFlow::Break(())) – driver is done, exit after current future completes
  • Poll::Pending – no progress

This function is allowed to block.

Implementors§

Source§

impl<'a, A, F> Driver<'a> for AsyncFnDriver<F, A>
where A: Arbitrary<'a>, F: AsyncFnMut(A) -> ControlFlow<()> + Unpin,

Source§

impl<'a, A, F> Driver<'a> for PollFnDriver<F, A>
where A: Arbitrary<'a>, F: FnMut(A) -> Poll<ControlFlow<()>>,

Source§

impl<'a, S, A> Driver<'a> for SinkDriver<S, A>
where A: Arbitrary<'a>, S: Sink<A, Error: Debug>,