Skip to main content

Frame

Struct Frame 

Source
pub struct Frame<'a> {
    pub opcode: u8,
    pub payload: &'a [u8],
}
Expand description

One parsed HID frame.

Holds a borrow into the underlying buffer. Lifetimes are tied to the buffer that was parsed, so a Frame is cheap to pass around without copies.

Fields§

§opcode: u8

First byte of the report: a CommandOpcode from the host or a ResponseStatus from the token, depending on direction.

§payload: &'a [u8]

Payload bytes (len bytes from the parsed report).

Implementations§

Source§

impl<'a> Frame<'a>

Source

pub fn parse(buf: &'a [u8]) -> Result<Self, FrameParseError>

Parse a HID report into a Frame.

Returns a frame borrowing into buf. The payload slice has the length declared in the header (len), not the report size. Padding bytes after the payload are not validated: they are ignored according to the protocol contract.

§Errors

See FrameParseError.

Source

pub fn write( opcode: u8, payload: &[u8], out: &mut [u8], ) -> Result<(), FrameBuildError>

Build a HID report from an opcode and a payload.

Writes into out (must be exactly HID_REPORT_SIZE long). All bytes past the payload are zeroed.

§Errors

Returns FrameBuildError::WrongOutputSize if out is not HID_REPORT_SIZE bytes, or FrameBuildError::PayloadTooLarge if payload.len() exceeds MAX_PAYLOAD_SIZE.

Source

pub fn to_report( opcode: u8, payload: &[u8], ) -> Result<[u8; 128], FrameBuildError>

Convenience wrapper around Frame::write that returns the report by value on the stack. Useful for callers that just want a buffer to hand to embassy-usb or to the OS HID layer.

§Errors

See Frame::write.

Trait Implementations§

Source§

impl<'a> Clone for Frame<'a>

Source§

fn clone(&self) -> Frame<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Frame<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Frame<'a>

Source§

fn eq(&self, other: &Frame<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for Frame<'a>

Source§

impl<'a> Eq for Frame<'a>

Source§

impl<'a> StructuralPartialEq for Frame<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Frame<'a>

§

impl<'a> RefUnwindSafe for Frame<'a>

§

impl<'a> Send for Frame<'a>

§

impl<'a> Sync for Frame<'a>

§

impl<'a> Unpin for Frame<'a>

§

impl<'a> UnsafeUnpin for Frame<'a>

§

impl<'a> UnwindSafe for Frame<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.