ReportItem

Enum ReportItem 

Source
pub enum ReportItem {
Show 28 variants Input(Input), Output(Output), Feature(Feature), Collection(Collection), EndCollection(EndCollection), UsagePage(UsagePage), LogicalMinimum(LogicalMinimum), LogicalMaximum(LogicalMaximum), PhysicalMinimum(PhysicalMinimum), PhysicalMaximum(PhysicalMaximum), UnitExponent(UnitExponent), Unit(Unit), ReportSize(ReportSize), ReportId(ReportId), ReportCount(ReportCount), Push(Push), Pop(Pop), Usage(Usage), UsageMinimum(UsageMinimum), UsageMaximum(UsageMaximum), DesignatorIndex(DesignatorIndex), DesignatorMinimum(DesignatorMinimum), DesignatorMaximum(DesignatorMaximum), StringIndex(StringIndex), StringMinimum(StringMinimum), StringMaximum(StringMaximum), Delimiter(Delimiter), Reserved(Reserved),
}
Expand description

Report items enumeration.

The HID Report descriptor is made up of items that provide information about the device.

All items contain a 1-byte prefix which denotes the basic type of the item. The HID class defines two basic formats for items:

  • Short items: 1–5 bytes total length; used for the most commonly occurring items. A short item typically contains 1 or 0 bytes of optional data.
  • Long items: 3–258 bytes in length; used for items that require larger data structures for parts.

NOTE: No long item tags are defined, these tags are reserved for future use.

The short item format packs the item size, type, and tag into the first byte. The first byte may be followed by 0, 1, 2, or 4 optional data bytes depending on the size of the data.

Bit -8Bit 7-4Bit 3-2Bit 1-0
[data]bTagbTypebSize

bSize: Numeric expression specifying size of data:

bSizesize of data
00 bytes
11 byte
22 bytes
34 bytes

bType: Numeric expression identifying type of item where:

bTypetype of item
0Main
1Global
2Local
3Reserved

bTag: Numeric expression specifying the function of the item.

Variants§

§

Input(Input)

An Input item.

§

Output(Output)

An Output item.

§

Feature(Feature)

A Feature item.

§

Collection(Collection)

A Collection item.

§

EndCollection(EndCollection)

An EndCollection item.

§

UsagePage(UsagePage)

A UsagePage item.

§

LogicalMinimum(LogicalMinimum)

§

LogicalMaximum(LogicalMaximum)

§

PhysicalMinimum(PhysicalMinimum)

§

PhysicalMaximum(PhysicalMaximum)

§

UnitExponent(UnitExponent)

A UnitExponent item.

§

Unit(Unit)

A Unit item.

§

ReportSize(ReportSize)

A ReportSize item.

§

ReportId(ReportId)

A ReportId item.

§

ReportCount(ReportCount)

A ReportCount item.

§

Push(Push)

A Push item.

§

Pop(Pop)

A Pop item.

§

Usage(Usage)

A Usage item.

§

UsageMinimum(UsageMinimum)

A UsageMinimum item.

§

UsageMaximum(UsageMaximum)

A UsageMaximum item.

§

DesignatorIndex(DesignatorIndex)

§

DesignatorMinimum(DesignatorMinimum)

§

DesignatorMaximum(DesignatorMaximum)

§

StringIndex(StringIndex)

A StringIndex item.

§

StringMinimum(StringMinimum)

A StringMinimum item.

§

StringMaximum(StringMaximum)

A StringMaximum item.

§

Delimiter(Delimiter)

A Delimiter item.

§

Reserved(Reserved)

A Reserved item.

Implementations§

Source§

impl ReportItem

Source

pub fn new(raw: &[u8]) -> Result<Self, HidError>

Create a new item from raw byte stream.

Items that cannot be recognized will be treated as Reserved. If you want to fail on unknown items, use new_strict() instead.

§Example
use hid_report::ReportItem;

let raw = [0x26, 0x3c, 0x02];
let item = ReportItem::new(&raw).unwrap();
assert!(matches!(item, ReportItem::LogicalMaximum(_)));
assert_eq!(item.to_string(), "Logical Maximum (572)");
Source

pub fn new_strict(raw: &[u8]) -> Result<Self, HidError>

Create a new item from raw byte stream in strict mode.

Items that cannot be recognized will be treated as HidError::ReservedItem.

Source

pub unsafe fn new_unchecked(raw: &[u8]) -> Self

Create a new item from raw byte stream, without checking data length.

Items that cannot be recognized will be treated as Reserved. If you want to fail on unknown items, use new_strict_unchecked() instead.

§Safety

You should ensure that the raw data is a valid HID report item.

Source

pub unsafe fn new_strict_unchecked(raw: &[u8]) -> Result<Self, HidError>

Create a new item from raw byte stream in strict mode, without checking data length.

Items that cannot be recognized will be treated as HidError::ReservedItem. Also, this is the only error that may be reported.

§Safety

You should ensure that the raw data is a valid HID report item.

Source

pub fn prefix(&self) -> u8

Get prefix part of the item. Equivalent to item.as_ref()[0].

Source

pub fn data(&self) -> &[u8]

Get data part of the item. Equivalent to &item.as_ref()[1..].

Trait Implementations§

Source§

impl AsRef<[u8]> for ReportItem

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for ReportItem

Source§

fn clone(&self) -> ReportItem

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 Debug for ReportItem

Source§

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

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

impl Display for ReportItem

Source§

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

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

impl PartialEq for ReportItem

Source§

fn eq(&self, other: &ReportItem) -> 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 Eq for ReportItem

Source§

impl StructuralPartialEq for ReportItem

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.