embassy-net-driver

Crates

git

Versions

default

Flavors

embassy_net_driver

Trait Driver

Source
pub trait Driver {
    type RxToken<'a>: RxToken
       where Self: 'a;
    type TxToken<'a>: TxToken
       where Self: 'a;

    // Required methods
    fn receive(
        &mut self,
        cx: &mut Context<'_>,
    ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>;
    fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>;
    fn link_state(&mut self, cx: &mut Context<'_>) -> LinkState;
    fn capabilities(&self) -> Capabilities;
    fn hardware_address(&self) -> HardwareAddress;
}
Expand description

Main embassy-net driver API.

This is essentially an interface for sending and receiving raw network frames.

The interface is based on tokens, which are types that allow to receive/transmit a single packet. The receive and transmit functions only construct such tokens, the real sending/receiving operation are performed when the tokens are consumed.

Required Associated Types§

Source

type RxToken<'a>: RxToken where Self: 'a

A token to receive a single network packet.

Source

type TxToken<'a>: TxToken where Self: 'a

A token to transmit a single network packet.

Required Methods§

Source

fn receive( &mut self, cx: &mut Context<'_>, ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>

Construct a token pair consisting of one receive token and one transmit token.

If there is a packet ready to be received, this function must return Some. If there isn’t, it must return None, and wake cx.waker() when a packet is ready.

The additional transmit token makes it possible to generate a reply packet based on the contents of the received packet. For example, this makes it possible to handle arbitrarily large ICMP echo (“ping”) requests, where the all received bytes need to be sent back, without heap allocation.

Source

fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>

Construct a transmit token.

If there is free space in the transmit buffer to transmit a packet, this function must return Some. If there isn’t, it must return None, and wake cx.waker() when space becomes available.

Note that TxToken::consume is infallible, so it is not allowed to return a token if there is no free space and fail later.

Get the link state.

This function must return the current link state of the device, and wake cx.waker() when the link state changes.

Source

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.

Source

fn hardware_address(&self) -> HardwareAddress

Get the device’s hardware address.

The returned hardware address also determines the “medium” of this driver. This indicates what kind of packet the sent/received bytes are, and determines some behaviors of the interface. For example, ARP/NDISC address resolution is only done for Ethernet mediums.

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.

Implementations on Foreign Types§

Source§

impl<T: ?Sized + Driver> Driver for &mut T

Source§

type RxToken<'a> = <T as Driver>::RxToken<'a> where Self: 'a

Source§

type TxToken<'a> = <T as Driver>::TxToken<'a> where Self: 'a

Source§

fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>

Source§

fn receive( &mut self, cx: &mut Context<'_>, ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>

Source§

fn capabilities(&self) -> Capabilities

Source§

fn hardware_address(&self) -> HardwareAddress

Implementors§