pub struct Buffer<const Q: usize, const N: usize> { /* private fields */ }
Expand description

HID-IO byte buffer This buffer is a queue of vecs with static allocation Each vec is fixed sized as HID-IO interface has a fixed transport payload (even if the actual size of the message is less). This buffer has no notion of packet size so it must store the full transport payload. In the minimal scenario a queue size of 1 is used.

Common HID-IO Vec capacities

  • 7 bytes (USB 2.0 LS /w HID ID byte)
  • 8 bytes (USB 2.0 LS)
  • 63 bytes (USB 2.0 FS /w HID ID byte)
  • 64 bytes (USB 2.0 FS)
  • 1023 bytes (USB 2.0 HS /w HID ID byte)
  • 1024 bytes (USB 2.0 HS)

The maximum queue size is 255

Implementations§

source§

impl<const Q: usize, const N: usize> Buffer<Q, N>

source

pub fn new() -> Buffer<Q, N>

Constructor for Buffer

Remarks

Initialize as blank This buffer has a limit of 65535 elements

source

pub fn peek(&self) -> Option<&Vec<u8, N>>

Checks the first item array Returns None if there are no items in the queue Does not dequeue

source

pub fn dequeue(&mut self) -> Option<Vec<u8, N>>

Dequeues and returns the first item array Returns None if there are no items in the queue

source

pub fn enqueue(&mut self, data: Vec<u8, N>) -> Result<(), Vec<u8, N>>

Enqueues Returns the array if there’s not enough space

source

pub fn clear(&mut self)

Clears the buffer Needed for some error conditions

source

pub fn capacity(&self) -> usize

Capacity of buffer

source

pub fn len(&self) -> usize

Number of elements stored in the buffer

source

pub fn is_empty(&self) -> bool

Buffer empty

source

pub fn is_full(&self) -> bool

Buffer full

Trait Implementations§

source§

impl<const Q: usize, const N: usize> Default for Buffer<Q, N>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const Q: usize, const N: usize> !RefUnwindSafe for Buffer<Q, N>

§

impl<const Q: usize, const N: usize> Send for Buffer<Q, N>

§

impl<const Q: usize, const N: usize> !Sync for Buffer<Q, N>

§

impl<const Q: usize, const N: usize> Unpin for Buffer<Q, N>

§

impl<const Q: usize, const N: usize> UnwindSafe for Buffer<Q, N>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.