pub struct FakeBindingsCtx<TimerId, Event: Debug, State, FrameMeta> {
    pub rng: FakeCryptoRng,
    pub timers: FakeTimerCtx<TimerId>,
    pub events: FakeEventCtx<Event>,
    pub frames: FakeFrameCtx<FrameMeta>,
    pub state: State,
}
Expand description

A test helper used to provide an implementation of a bindings context.

Fields§

§rng: FakeCryptoRng

Provides RngContext.

§timers: FakeTimerCtx<TimerId>

Provides TimerContext.

§events: FakeEventCtx<Event>

Provides EventContext.

§frames: FakeFrameCtx<FrameMeta>

Provides [SendFrameContext].

§state: State

Generic state used by specific tests.

Implementations§

source§

impl<TimerId, Event: Debug, State, FrameMeta> FakeBindingsCtx<TimerId, Event, State, FrameMeta>

source

pub fn seed_rng(&mut self, seed: u128)

Seed the testing RNG with a specific value.

source

pub fn take_events(&mut self) -> Vec<Event>

Takes all the accumulated events from the FakeEventCtx.

Trait Implementations§

source§

impl<Id, Event: Debug, State, FrameMeta> AsMut<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn as_mut(&mut self) -> &mut FakeTimerCtx<Id>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<Id, Event: Debug, State, FrameMeta> AsRef<FakeInstantCtx> for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn as_ref(&self) -> &FakeInstantCtx

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<Id, Event: Debug, State, FrameMeta> AsRef<FakeTimerCtx<Id>> for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn as_ref(&self) -> &FakeTimerCtx<Id>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<TimerId, Event: Debug, State, FrameMeta> ContextProvider for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

§

type Context = FakeBindingsCtx<TimerId, Event, State, FrameMeta>

The context provided by this ContextProvider.
source§

fn context(&mut self) -> &mut Self::Context

Gets a mutable borrow to this context.
source§

impl<TimerId, Event: Debug, State: Default, FrameMeta> Default for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<Id, Event: Debug, State, FrameMeta> DeferredResourceRemovalContext for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn defer_removal<T: Send + 'static>( &mut self, receiver: Self::ReferenceReceiver<T> )

Defers the removal of some resource T to bindings. Read more
source§

fn defer_removal_result<T: Send + 'static>( &mut self, result: RemoveResourceResultWithContext<T, Self> )

A shorthand for [defer_removal] that takes a ReferenceReceiver from the Deferred variant of a RemoveResourceResult. Read more
source§

impl<Id, Event: Debug, State, FrameMeta> EventContext<Event> for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn on_event(&mut self, event: Event)

Handles event.
source§

impl<Id, Event: Debug, State, FrameMeta> ReferenceNotifiers for FakeBindingsCtx<Id, Event, State, FrameMeta>

§

type ReferenceReceiver<T: 'static> = Infallible

The receiver for shared reference destruction notifications.
§

type ReferenceNotifier<T: Send + 'static> = Infallible

The notifier for shared reference destruction notifications.
source§

fn new_reference_notifier<T: Send + 'static>( debug_references: DynDebugReferences ) -> (Self::ReferenceNotifier<T>, Self::ReferenceReceiver<T>)

Creates a new Notifier/Receiver pair for T. Read more
source§

impl<TimerId, Event: Debug, State, FrameMeta> RngContext for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

§

type Rng<'a> = FakeCryptoRng where Self: 'a

The random number generator (RNG) provided by this RngContext. Read more
source§

fn rng(&mut self) -> Self::Rng<'_>

Gets the random number generator (RNG).
source§

impl<Id: Debug + PartialEq + Clone + Send + Sync, Event: Debug, State, FrameMeta> TimerBindingsTypes for FakeBindingsCtx<Id, Event, State, FrameMeta>

§

type Timer = <FakeTimerCtx<Id> as TimerBindingsTypes>::Timer

State for a timer created through TimerContext.
§

type DispatchId = <FakeTimerCtx<Id> as TimerBindingsTypes>::DispatchId

The type used to dispatch fired timers from bindings to core.
source§

impl<Id: Debug + PartialEq + Clone + Send + Sync, Event: Debug, State, FrameMeta> TimerContext for FakeBindingsCtx<Id, Event, State, FrameMeta>

source§

fn new_timer(&mut self, id: Self::DispatchId) -> Self::Timer

Creates a new timer that dispatches id back to core when fired. Read more
source§

fn schedule_timer_instant( &mut self, time: Self::Instant, timer: &mut Self::Timer ) -> Option<Self::Instant>

Schedule a timer to fire at some point in the future. Returns the previously scheduled instant, if this timer was scheduled.
source§

fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>

Cancel a timer. Read more
source§

fn scheduled_instant(&self, timer: &mut Self::Timer) -> Option<Self::Instant>

Get the instant a timer will fire, if one is scheduled.
source§

fn schedule_timer( &mut self, duration: Duration, timer: &mut Self::Timer ) -> Option<Self::Instant>

Like [schedule_timer_instant] but schedules a time for duration in the future.
source§

impl<Id, Event: Debug, State, FrameMeta> TracingContext for FakeBindingsCtx<Id, Event, State, FrameMeta>

§

type DurationScope = ()

The scope of a trace duration. Read more
source§

fn duration(&self, _: &'static CStr)

Writes a duration event which ends when the returned scope is dropped. Read more
source§

impl<TimerId, Event: Debug, State, FrameMeta> WithFakeTimerContext<TimerId> for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

source§

fn with_fake_timer_ctx<O, F: FnOnce(&FakeTimerCtx<TimerId>) -> O>( &self, f: F ) -> O

Calls the callback with a borrow of FakeTimerCtx.
source§

fn with_fake_timer_ctx_mut<O, F: FnOnce(&mut FakeTimerCtx<TimerId>) -> O>( &mut self, f: F ) -> O

Calls the callback with a mutable borrow of FakeTimerCtx.

Auto Trait Implementations§

§

impl<TimerId, Event, State, FrameMeta> Freeze for FakeBindingsCtx<TimerId, Event, State, FrameMeta>
where State: Freeze,

§

impl<TimerId, Event, State, FrameMeta> !RefUnwindSafe for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

§

impl<TimerId, Event, State, FrameMeta> Send for FakeBindingsCtx<TimerId, Event, State, FrameMeta>
where State: Send, Event: Send, FrameMeta: Send, TimerId: Send,

§

impl<TimerId, Event, State, FrameMeta> !Sync for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

§

impl<TimerId, Event, State, FrameMeta> Unpin for FakeBindingsCtx<TimerId, Event, State, FrameMeta>
where State: Unpin, Event: Unpin, FrameMeta: Unpin, TimerId: Unpin,

§

impl<TimerId, Event, State, FrameMeta> !UnwindSafe for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

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
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<Id, Ctx> FakeTimerCtxExt<Id> for Ctx
where Id: Clone, Ctx: WithFakeTimerContext<Id>,

source§

fn trigger_next_timer<H>(&mut self, handler: &mut H) -> Option<Id>
where H: TimerHandler<Ctx, Id>,

Triggers the next timer, if any, by calling f on it.

trigger_next_timer triggers the next timer, if any, advances the internal clock to the timer’s scheduled time, and returns its ID.

source§

fn trigger_timers_until_instant<H>( &mut self, instant: FakeInstant, handler: &mut H ) -> Vec<Id>
where H: TimerHandler<Ctx, Id>,

Skips the current time forward until instant, triggering all timers until then, inclusive, by giving them to handler.

Returns the timers which were triggered.

§Panics

Panics if instant is in the past.

source§

fn trigger_timers_for<H>( &mut self, duration: Duration, handler: &mut H ) -> Vec<Id>
where H: TimerHandler<Ctx, Id>,

Skips the current time forward by duration, triggering all timers until then, inclusive, by calling f on them.

Returns the timers which were triggered.

source§

fn trigger_timers_and_expect_unordered<I, H>( &mut self, timers: I, handler: &mut H )
where I: IntoIterator<Item = Id>, H: TimerHandler<Ctx, Id>, Id: Debug + Hash + Eq,

Triggers timers and expects them to be the given timers.

The number of timers to be triggered is taken to be the number of timers produced by timers. Timers may be triggered in any order.

§Panics

Panics under the following conditions:

  • Fewer timers could be triggered than expected
  • Timers were triggered that were not expected
  • Timers that were expected were not triggered
source§

fn trigger_timers_until_and_expect_unordered<I, H>( &mut self, instant: FakeInstant, timers: I, handler: &mut H )
where I: IntoIterator<Item = Id>, H: TimerHandler<Ctx, Id>, Id: Debug + Hash + Eq,

Triggers timers until instant and expects them to be the given timers.

Like trigger_timers_and_expect_unordered, except that timers will only be triggered until instant (inclusive).

source§

fn trigger_timers_for_and_expect<I, H>( &mut self, duration: Duration, timers: I, handler: &mut H )
where I: IntoIterator<Item = Id>, H: TimerHandler<Ctx, Id>, Id: Debug + Hash + Eq,

Triggers timers for duration and expects them to be the given timers.

Like trigger_timers_and_expect_unordered, except that timers will only be triggered for duration (inclusive).

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> InstantBindingsTypes for T

§

type Instant = FakeInstant

The type of an instant in time. Read more
source§

impl<T> InstantContext for T

source§

fn now(&self) -> FakeInstant

Returns the current instant. 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<CC, BC, Meta> RecvFrameContext<BC, Meta> for CC
where Meta: ReceivableFrameMeta<CC, BC>,

source§

fn receive_frame<B>(&mut self, bindings_ctx: &mut BC, metadata: Meta, frame: B)
where B: BufferMut + Debug,

Receive a frame. Read more
source§

impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CC
where Meta: SendableFrameMeta<CC, BC>,

source§

fn send_frame<S>( &mut self, bindings_ctx: &mut BC, metadata: Meta, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Send a frame. Read more
source§

impl<Meta, BC> SendableFrameMeta<FakeFrameCtx<Meta>, BC> for Meta

source§

fn send_meta<S>( self, core_ctx: &mut FakeFrameCtx<Meta>, _bindings_ctx: &mut BC, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Sends this frame metadata to the provided contexts.
source§

impl<Id, CC, BC> TimerHandler<BC, Id> for CC
where Id: HandleableTimer<CC, BC>,

source§

fn handle_timer(&mut self, bindings_ctx: &mut BC, id: Id)

Handle a timer firing.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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