Trait FakeNetworkSpec

Source
pub trait FakeNetworkSpec: Sized {
    type Context: WithFakeTimerContext<Self::TimerId>;
    type TimerId: Clone;
    type SendMeta;
    type RecvMeta;

    // Required methods
    fn handle_frame(
        ctx: &mut Self::Context,
        recv: Self::RecvMeta,
        data: Buf<Vec<u8>>,
    );
    fn handle_timer(
        ctx: &mut Self::Context,
        dispatch: Self::TimerId,
        timer: FakeTimerId,
    );
    fn process_queues(ctx: &mut Self::Context) -> bool;
    fn fake_frames(
        ctx: &mut Self::Context,
    ) -> &mut impl WithFakeFrameContext<Self::SendMeta>;

    // Provided method
    fn new_network<CtxId, Links, I>(
        contexts: I,
        links: Links,
    ) -> FakeNetwork<Self, CtxId, Links>
       where CtxId: Eq + Hash + Copy + Debug,
             I: IntoIterator<Item = (CtxId, Self::Context)>,
             Links: FakeNetworkLinks<Self::SendMeta, Self::RecvMeta, CtxId> { ... }
}
Expand description

A network spec that defines a FakeNetwork.

Required Associated Types§

Source

type Context: WithFakeTimerContext<Self::TimerId>

The context type, which represents a node in the network.

Source

type TimerId: Clone

The type of timer IDs handled by Self::Context.

Source

type SendMeta

The type of metadata associated with frames sent by this nodes in the network.

Source

type RecvMeta

The type of metadata associated with frames received by nodes in the network.

Required Methods§

Source

fn handle_frame( ctx: &mut Self::Context, recv: Self::RecvMeta, data: Buf<Vec<u8>>, )

Handles a single received frame by ctx.

Source

fn handle_timer( ctx: &mut Self::Context, dispatch: Self::TimerId, timer: FakeTimerId, )

Handles a single timer id in ctx.

dispatch is the timer’s dispatch identifier, i.e., an implementer of HandleableTimer. timer is the unique timer identifier for the fake timer that fired.

Source

fn process_queues(ctx: &mut Self::Context) -> bool

Processes any context-internal queues, returning true if any work was done.

This is used to drive queued frames that may be sitting inside the context and invisible to the FakeNetwork.

Source

fn fake_frames( ctx: &mut Self::Context, ) -> &mut impl WithFakeFrameContext<Self::SendMeta>

Extracts accesses to fake frames from Self::Context.

Provided Methods§

Source

fn new_network<CtxId, Links, I>( contexts: I, links: Links, ) -> FakeNetwork<Self, CtxId, Links>
where CtxId: Eq + Hash + Copy + Debug, I: IntoIterator<Item = (CtxId, Self::Context)>, Links: FakeNetworkLinks<Self::SendMeta, Self::RecvMeta, CtxId>,

Creates a new fake network from this spec.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§