Skip to main content

PacketLink

Trait PacketLink 

Source
pub trait PacketLink {
    // Required methods
    fn max_packet_len(&self) -> usize;
    async fn send(&mut self, packet: &[u8]) -> Result<()>;
    async fn receive(&mut self, timeout: Duration) -> Result<Vec<u8>>;
    async fn purge(&mut self) -> Result<()>;
}
Expand description

A packet link that keeps message boundaries: USB HID reports, USB bulk transfers or BLE characteristic writes and notifications.

Required Methods§

Source

fn max_packet_len(&self) -> usize

The largest packet send accepts, in bytes. For BLE this is the ATT MTU minus 3.

Source

async fn send(&mut self, packet: &[u8]) -> Result<()>

Sends one packet of at most max_packet_len bytes.

§Errors

A transport error if the send fails.

Source

async fn receive(&mut self, timeout: Duration) -> Result<Vec<u8>>

Receives the next packet.

§Errors

Error::Timeout if no packet arrives within timeout, or a transport error.

Source

async fn purge(&mut self) -> Result<()>

Discards any received packets that have not been read yet.

§Errors

A transport error if the backend cannot purge.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§