Skip to main content

Device

Trait Device 

Source
pub trait Device {
    type Handle: Handle + ?Sized;
    type Payload: Payload + ?Sized;

    // Required methods
    fn personality(&self) -> Personality;
    fn tx(
        &mut self,
        max: usize,
        sender: impl Send<Self::Handle, Self::Payload>,
    ) -> Result<usize>;
    fn rx(
        &mut self,
        max: usize,
        receiver: impl Recv<Self::Handle, Self::Payload>,
    ) -> Result<usize>;
}
Expand description

A layer 2 device.

Required Associated Types§

Source

type Handle: Handle + ?Sized

The control handle type also providing packet meta information.

Source

type Payload: Payload + ?Sized

The payload buffer type of this device.

It can be an owning buffer such as Vec<u8> or a non-owning buffer or even only emulate a buffer containing an Ethernet packet. Note that the buffer trait should stay a type parameter so that upper layers can make use of additional methods and not be constrained to the Payload trait. (Although smart use of Any might in some cases suffice in a real, specific network stack that is not this library).

Required Methods§

Source

fn personality(&self) -> Personality

A description of the device.

Could be dynamically configured but the optimizer and the user is likely happier if the implementation does not take advantage of this fact.

Source

fn tx( &mut self, max: usize, sender: impl Send<Self::Handle, Self::Payload>, ) -> Result<usize>

Transmit some packets utilizing the sender.

Up to max packet buffers are chosen by the device. They are provided to the sender callback which may initialize their contents and decide to queue them. Afterwards, the device is responsible for cleaning up unused buffers and physically sending queued buffers.

Source

fn rx( &mut self, max: usize, receiver: impl Recv<Self::Handle, Self::Payload>, ) -> Result<usize>

Receive packet utilizing the receptor.

Dequeue up to max received packets and provide them to the receiver callback.

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§

Source§

impl<'a, C: PayloadMut> Device for Loopback<'a, C>

Source§

impl<D> Device for Lossy<'_, D>
where D: Device,

Source§

impl<T, P> Device for External<T>
where T: Deref<Target = [P]> + DerefMut, P: Payload,