Skip to main content

KnownUnit

Enum KnownUnit 

Source
#[non_exhaustive]
pub enum KnownUnit {
Show 23 variants None = 0, Centimeter = 17, Radian = 18, Inch = 19, Degree = 20, Gram = 257, Seconds = 4_097, Hertz = 61_441, SiVelocity = 61_457, SiMomentum = 61_713, SiAcceleration = 57_361, SiForce = 57_617, SiEnergy = 57_633, SiAngularVelocity = 61_458, DegAngularVelocity = 61_460, SiAngularAcceleration = 57_362, DegAngularAcceleration = 57_364, Kelvin = 65_537, DegreesFahrenheit = 65_539, Current = 1_048_577, AmpSeconds = 1_052_673, Voltage = 15_782_177, SiPower = 53_537,
}
Expand description

Identifiers for some known Unit values.

Due to the complexity of the HID unit system, this enum does not attempt to represent all the possible unit values.

Unit values are 32 bits long, split into 8 nibbles (4-bit fields).

The lowest nibble (bits 3..0) specify a unit system:

  • 1: SI Linear
  • 2: SI Rotation
  • 3: English Linear
  • 4: English Rotation

The other 5 nibbles are dedicated to individual unit categories:

  • nibble 1 (bits 7..4): Length (Centimeter, Radian, Inch, or Degree)
  • nibble 2 (bits 11..8): Mass (Gram or Slug)
  • nibble 3 (bits ..12): Time (Seconds in all systems)
  • nibble 4 (bits ..16): Temperature (Kelvin or Fahrenheit)
  • nibble 5 (bits ..20): Current (Ampere in all systems)
  • nibble 6 (bits ..24): Luminous Intensity (Candela in all systems)
  • nibble 7 (bits 31..28): reserved

The value in each nibble is a signed integer from -8 to +7, and that integer is the exponent attached to each unit. For example:

  • 0x23 is Length^2 in the English Linear system, or Inch^2.
  • 0x101 is Mass^1 in the SI Linear system, or Gram.
  • 0xF011 is Time^-1 * Length^1, or Centimeters/Second.

See Device Class Definition for Human Interface Devices, section 6.2.2.7 for more details.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

None = 0

No unit.

§

Centimeter = 17

SI unit of length.

§

Radian = 18

SI unit of rotation.

§

Inch = 19

English unit of length.

§

Degree = 20

English unit of rotation.

§

Gram = 257

SI unit of mass.

§

Seconds = 4_097

SI unit of time.

§

Hertz = 61_441

SI unit of frequency, Hertz aka second⁻¹)

§

SiVelocity = 61_457

SI unit of velocity (centimeters/second).

§

SiMomentum = 61_713

SI unit of momentum (gram·centimeter/second).

§

SiAcceleration = 57_361

SI unit of acceleration (centimeters/second²).

§

SiForce = 57_617

SI unit of force (gram·centimeter/second²).

Divide by 10⁵ to get Newtons (kg·m/s²).

§

SiEnergy = 57_633

SI unit of energy (gram·centimeter²/second²).

Divide by 10⁷ to get Joules (kg·m²/s²).

§

SiAngularVelocity = 61_458

SI unit of Angular Velocity (radians/second).

§

DegAngularVelocity = 61_460

English unit of Angular Acceleration (degrees/second).

§

SiAngularAcceleration = 57_362

SI unit of Angular Acceleration (radians/second²).

§

DegAngularAcceleration = 57_364

English unit of Angular Acceleration (degrees/second²).

§

Kelvin = 65_537

SI unit of temperature.

§

DegreesFahrenheit = 65_539

English unit of temperature.

§

Current = 1_048_577

SI unit of current (amperes).

§

AmpSeconds = 1_052_673

SI unit for amp·seconds.

This unit can be used as “battery capacity”. See Usage Tables for HID Power Devices.

§

Voltage = 15_782_177

SI unit of Voltage (gram·centimeter²/amp·seconds³).

Divide by 10⁷ to get Volts (kg·m²/amp·seconds³).

§

SiPower = 53_537

SI unit of power (gram-centimeter²/seconds³).

Divide by 10⁷ to get Watts or Volt-Amps (kg·m²/s³).

Trait Implementations§

Source§

impl Clone for KnownUnit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for KnownUnit

Source§

impl Debug for KnownUnit

Source§

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

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

impl From<KnownUnit> for u32

Source§

fn from(enum_value: KnownUnit) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for KnownUnit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KnownUnit

Source§

impl TryFrom<u32> for KnownUnit

Source§

type Error = TryFromPrimitiveError<KnownUnit>

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

fn try_from(number: u32) -> Result<Self, TryFromPrimitiveError<Self>>

Performs the conversion.
Source§

impl TryFromPrimitive for KnownUnit

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.