Skip to main content

SimReceiver

Struct SimReceiver 

Source
pub struct SimReceiver<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(/* private fields */);
Available on crate feature sim only.
Expand description

A receiver for an external bincode stream in a simulation.

Implementations§

Source§

impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> SimReceiver<T, O, R>

Source

pub fn assert_no_more(self) -> impl Future<Output = ()>
where T: Debug,

Asserts that the stream has ended and no more messages can possibly arrive.

If the check cannot be answered without running pending nondeterministic work (such as ticks with buffered inputs):

  • Under CompiledSim::exhaustive, the search forks: one instance performs the check and ends there, while sibling instances skip the check and continue.
  • In other modes, the pending work runs; afterwards, sending more input and then attempting to receive output will panic.
Source§

impl<T: Serialize + DeserializeOwned> SimReceiver<T, TotalOrder, ExactlyOnce>

Source

pub fn next(&self) -> impl use<'_, T> + Future<Output = T>

Receives the next message from the external bincode stream, waiting (and letting the scheduler run any pending simulation work) until one is available. If the simulation becomes quiescent without producing a message, the test fails.

This is safe to use in the middle of a test; to observe the absence of a message, use Self::try_next or Self::assert_no_more.

Source

pub async fn try_next(&self) -> Option<T>

Receives the next message from the external bincode stream, or returns None if no more messages can possibly arrive.

If answering requires forcing pending nondeterministic work to run, then afterwards, sending more input and then attempting to receive output will panic. Prefer Self::next (or Self::assert_no_more) when possible.

Source

pub fn collect_n<C: Default + Extend<T>>( &self, n: usize, ) -> impl use<'_, T, C> + Future<Output = C>

Receives the next n messages from the external bincode stream, waiting (and letting the scheduler run any pending simulation work) until they are available. If the simulation becomes quiescent before n messages arrive, the test fails.

Like Self::next, this is safe to use in the middle of a test. It does not check that the stream ends afterwards; use Self::collect_n_only for that.

Source

pub async fn collect_n_only<C: Default + Extend<T>>(self, n: usize) -> C
where T: Debug,

Receives the next n messages (like Self::collect_n) and then asserts that the stream ends (like Self::assert_no_more, forking the search in exhaustive mode).

Source

pub async fn collect<C: Default + Extend<T>>(self) -> C

Collects all remaining messages from the external bincode stream into a collection, waiting until no more messages can possibly arrive.

If this has to force pending nondeterministic work to run, it should be the last observation of the test: afterwards, sending more input and then attempting to receive output will panic. When the number of expected messages is known, prefer Self::collect_n / Self::collect_n_only.

Source

pub fn assert_yields<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
where T: Debug + PartialEq<T2>,

Asserts that the stream yields exactly the expected sequence of messages, in order. This does not check that the stream ends, use Self::assert_yields_only for that.

Like Self::next, this is safe to use in the middle of a test.

Source

pub fn assert_yields_only<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
where T: Debug + PartialEq<T2>,

Asserts that the stream yields only the expected sequence of messages, in order, and then ends (like Self::assert_no_more, forking the search in exhaustive mode).

Source§

impl<T: Serialize + DeserializeOwned> SimReceiver<T, NoOrder, ExactlyOnce>

Source

pub fn collect_n_sorted<C: Default + Extend<T> + AsMut<[T]>>( &self, n: usize, ) -> impl use<'_, T, C> + Future<Output = C>
where T: Ord,

Receives the next n messages, sorted, waiting (and letting the scheduler run any pending simulation work) until they are available. If the simulation becomes quiescent before n messages arrive, the test fails.

Like SimReceiver::next, this is safe to use in the middle of a test.

Source

pub async fn collect_sorted<C: Default + Extend<T> + AsMut<[T]>>(self) -> C
where T: Ord,

Collects all remaining messages from the external bincode stream into a collection, sorting them. This will wait until no more messages can possibly arrive.

If this has to force pending nondeterministic work to run, it should be the last observation of the test; see collect.

Source

pub fn assert_yields_unordered<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
where T: Debug + PartialEq<T2>,

Asserts that the stream yields exactly the expected sequence of messages, in some order. This does not check that the stream ends, use Self::assert_yields_only_unordered for that.

Like SimReceiver::next, this is safe to use in the middle of a test.

Source

pub fn assert_yields_only_unordered<T2: Debug, I: IntoIterator<Item = T2>>( &self, expected: I, ) -> impl use<'_, T, T2, I> + Future<Output = ()>
where T: Debug + PartialEq<T2>,

Asserts that the stream yields only the expected sequence of messages, in some order, and then ends (like Self::assert_no_more, forking the search in exhaustive mode).

Trait Implementations§

Source§

impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> Clone for SimReceiver<T, O, R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Serialize + DeserializeOwned, O: Ordering, R: Retries> Copy for SimReceiver<T, O, R>

Auto Trait Implementations§

§

impl<T, O, R> Freeze for SimReceiver<T, O, R>

§

impl<T, O, R> RefUnwindSafe for SimReceiver<T, O, R>

§

impl<T, O, R> Send for SimReceiver<T, O, R>
where T: Send, O: Send, R: Send,

§

impl<T, O, R> Sync for SimReceiver<T, O, R>
where T: Sync, O: Sync, R: Sync,

§

impl<T, O, R> Unpin for SimReceiver<T, O, R>
where T: Unpin, O: Unpin, R: Unpin,

§

impl<T, O, R> UnsafeUnpin for SimReceiver<T, O, R>

§

impl<T, O, R> UnwindSafe for SimReceiver<T, O, R>
where T: UnwindSafe, O: UnwindSafe, R: UnwindSafe,

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
§

impl<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSinkBuild for T

Source§

fn iter_to_sink_build(self) -> SendIterBuild<Self>
where Self: Sized + Iterator,

Starts a SinkBuild adaptor chain to send all items from self as an Iterator.
Source§

fn stream_to_sink_build(self) -> SendStreamBuild<Self>
where Self: Sized + Stream,

Starts a SinkBuild adaptor chain to send all items from self as a [Stream].
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more