ArrayField

Struct ArrayField 

Source
pub struct ArrayField {
    pub bits: Range<usize>,
    pub report_count: ReportCount,
    pub logical_minimum: LogicalMinimum,
    pub logical_maximum: LogicalMaximum,
    pub physical_minimum: Option<PhysicalMinimum>,
    pub physical_maximum: Option<PhysicalMaximum>,
    pub unit: Option<Unit>,
    pub unit_exponent: Option<UnitExponent>,
    pub collections: Vec<Collection>,
    /* private fields */
}
Expand description

An ArrayField represents a group of physical controls, see section 6.2.2.5.

An array provides an alternate means for describing the data returned from a group of buttons. Arrays are more efficient, if less flexible than variable items. Rather than returning a single bit for each button in the group, an array returns an index in each field that corresponds to the pressed button

Fields§

§bits: Range<usize>§report_count: ReportCount§logical_minimum: LogicalMinimum§logical_maximum: LogicalMaximum§physical_minimum: Option<PhysicalMinimum>§physical_maximum: Option<PhysicalMaximum>§unit: Option<Unit>§unit_exponent: Option<UnitExponent>§collections: Vec<Collection>

Implementations§

Source§

impl ArrayField

Source

pub fn usages(&self) -> &[Usage]

Returns the set of usages for this field. This is the inclusive range of UsageMinimum..=UsageMaximum as defined for this field.

In most cases it’s better to use usage_range() instead.

Source

pub fn usage_range(&self) -> UsageRange

Returns the UsageRange for this field.

Source

pub fn is_signed(&self) -> bool

Returns true if this field contains signed values,. i.e. the LogicalMinimum is less than zero.

Source

pub fn extract(&self, bytes: &[u8]) -> Result<Vec<FieldValue>, ParserError>

Extract this field’s value as FieldValue from a report’s bytes. The value is extracted as its correct bit size, the returned FieldValue can then be casted in to a u32, i32, etc. via the From trait.

if field.is_signed() {
    println!("Signed values: {:?}", field
        .extract(bytes)
        .unwrap()
        .iter()
        .map(i32::from)
        .collect::<Vec<i32>>());
} else {
    println!("Unsigned values: {:?}", field
        .extract(bytes)
        .unwrap()
        .iter()
        .map(u32::from)
        .collect::<Vec<u32>>());
}
Source

pub fn extract_one( &self, bytes: &[u8], idx: usize, ) -> Result<FieldValue, ParserError>

Extract a single value from this array. See ArrayField::extract.

The index must be less than Self::report_count.

Trait Implementations§

Source§

impl Clone for ArrayField

Source§

fn clone(&self) -> ArrayField

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 ArrayField

Source§

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

Formats the value using the given formatter. Read more

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, 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.