#[non_exhaustive]pub enum Value {
Int8(i8),
Int16(i16),
Int32(i32),
Float(f32),
}Expand description
A decoded register value from the multiplex protocol.
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.
Int8(i8)
8-bit signed integer
Int16(i16)
16-bit signed integer
Int32(i32)
32-bit signed integer
Float(f32)
32-bit IEEE 754 float
Implementations§
Source§impl Value
impl Value
Sourcepub fn to_i32(&self) -> i32
pub fn to_i32(&self) -> i32
Returns the raw integer value.
Float values are cast to i32. This should only be used for registers which are intended to hold an integer type, and thus can not store a non-finite value.
Sourcepub fn to_f32(&self, scaling: &Scaling) -> f32
pub fn to_f32(&self, scaling: &Scaling) -> f32
Returns the value as f32, applying NaN mapping and scaling.
Integer minimum values (e.g., -128 for Int8) are mapped to NaN. Integer values are multiplied by the appropriate scaling factor. Float values are returned directly.
§Examples
use moteus_protocol::Value;
use moteus_protocol::scaling;
let raw = Value::Int16(5000);
let position = raw.to_f32(&scaling::POSITION);
assert!((position - 0.5).abs() < 0.001); // 5000 * 0.0001 = 0.5 revTrait Implementations§
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
impl UnwindSafe for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more