ariel_os::reexports::embassy_net::driver

Trait Driver

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§

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

A token to receive a single network packet.

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

A token to transmit a single network packet.

Required Methods§

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.

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.

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.

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§

§

impl<'d, const MTU: usize> Driver for Device<'d, MTU>

§

fn transmit( &mut self, cx: &mut Context<'_>, ) -> Option<<Device<'d, MTU> as Driver>::TxToken<'_>>

Construct a transmit token.

§

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.

§

type RxToken<'a> = RxToken<'a, MTU> where Device<'d, MTU>: 'a

§

type TxToken<'a> = TxToken<'a, MTU> where Device<'d, MTU>: 'a

§

fn receive( &mut self, cx: &mut Context<'_>, ) -> Option<(<Device<'d, MTU> as Driver>::RxToken<'_>, <Device<'d, MTU> as Driver>::TxToken<'_>)>

§

fn hardware_address(&self) -> HardwareAddress

§

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

§

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

§

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

§

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

§

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

§

fn capabilities(&self) -> Capabilities

§

fn hardware_address(&self) -> HardwareAddress

Implementors§