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§
Sourcetype Payload: Payload + ?Sized
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§
Sourcefn personality(&self) -> Personality
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.
Sourcefn tx(
&mut self,
max: usize,
sender: impl Send<Self::Handle, Self::Payload>,
) -> Result<usize>
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.
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.