Struct FakeBindingsCtx

Source
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<TimerId, Event: Debug, State, FrameMeta> ContextProvider for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

Source§

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<TimerId, Event: Debug, State, FrameMeta> InstantBindingsTypes for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

Source§

type Instant = FakeInstant

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

type AtomicInstant = FakeAtomicInstant

An atomic representation of Self::Instant.
Source§

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

Source§

fn now(&self) -> Self::Instant

Returns the current instant. Read more
Source§

fn now_atomic(&self) -> Self::AtomicInstant

Returns the current instant, as an [Self::AtomicInstant].
Source§

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

Source§

type ReferenceReceiver<T: 'static> = Infallible

The receiver for shared reference destruction notifications.
Source§

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>

Source§

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>

Source§

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

State for a timer created through TimerContext.
Source§

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

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

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

A value that uniquely identifiers a Timer. It is given along with the DispatchId whenever a timer is fired. Read more
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 unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId

Retrieves the timer id for timer. Read more
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<TimerId, Event: Debug, State, FrameMeta> TxMetadataBindingsTypes for FakeBindingsCtx<TimerId, Event, State, FrameMeta>

Source§

type TxMetadata = FakeTxMetadata

The metadata associated with a TX frame.
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.
Source§

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

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<O, BC> BuildableCoreContext<BC> for O
where O: Default,

Source§

type Builder = ()

The builder type that can build this core context.
Source§

fn build(_bindings_ctx: &mut BC, _: ()) -> O

Consumes this builder and returns the context.
§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<Id, Ctx> FakeTimerCtxExt<Id> for Ctx
where Id: Clone, Ctx: WithFakeTimerContext<Id> + TimerBindingsTypes<UniqueTimerId = FakeTimerId>,

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, 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<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<CC, BC, Meta> RecvFrameContext<Meta, BC> 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<N> ReferenceNotifiersExt for N

Source§

fn unwrap_or_notify_with_new_reference_notifier<S: Send + Sync + 'static, O: Send, F: Send + Copy + 'static + FnOnce(S) -> O>( primary: PrimaryRc<S>, map: F, ) -> RemoveResourceResultWithContext<O, Self>

Unwraps a PrimaryRc if it has no pending references, otherwise notifying with [Self::ReferenceNotifier]. 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<(), ErrorAndSerializer<SendFrameErrorReason, S>>

Send a frame. Read more
Source§

impl<BC, S, Meta, DeviceId> SendableFrameMeta<FakeCoreCtx<S, Meta, DeviceId>, BC> for Meta

Source§

fn send_meta<SS>( self, core_ctx: &mut FakeCoreCtx<S, Meta, DeviceId>, bindings_ctx: &mut BC, frame: SS, ) -> Result<(), ErrorAndSerializer<SendFrameErrorReason, SS>>
where SS: Serializer, <SS as Serializer>::Buffer: BufferMut,

Sends this frame metadata to the provided contexts.
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<(), ErrorAndSerializer<SendFrameErrorReason, S>>

Sends this frame metadata to the provided contexts.
Source§

impl<T, O> SettingsContext<T> for O
where T: Default + 'static, O: AlwaysDefaultsSettingsContext,

Source§

fn settings(&self) -> impl Deref<Target = T>

Borrows the current settings values.
Source§

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

Source§

fn handle_timer( &mut self, bindings_ctx: &mut BC, dispatch: Id, timer: <BC as TimerBindingsTypes>::UniqueTimerId, )

Handle a timer firing. Read more
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<L, T> UnlockedAccess<L> for T
where L: UnlockedAccessMarkerFor<T>,

§

type Data = <L as UnlockedAccessMarkerFor<T>>::Data

The type of state being accessed.
§

type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data where T: 'l

A guard providing read access to the data.
§

fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>

How to access the state.
§

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

§

fn vzip(self) -> V

§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,