pub enum Value {
U8(u8),
U16(u16),
U32(u32),
U64(u64),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
F16(f16),
F32(f32),
F64(f64),
}Expand description
§Typed data value
This enum supports all the data types that can be exchanged with the Crazyflie using the log and param subsystems.
A function allows to convert a [u8] to a Value and the Into<Vec<u8>>
trait is implemented to convert a Value into a vector of bytes.
The TryFrom trait is implemented for all matching rust primitive type. There is only direct conversion implemented. For example the following is OK:
let v:u32 = Value::U32(42).try_into().unwrap();However the following will panic:
let v:u32 = Value::U8(42).try_into().unwrap();Variants§
U8(u8)
u8 value
U16(u16)
u16 value
U32(u32)
u32 value
U64(u64)
u64 value
I8(i8)
i8 value
I16(i16)
i16 value
I32(i32)
i32 value
I64(i64)
i64 value
F16(f16)
f16 value
F32(f32)
f32 value
F64(f64)
f64 value
Implementations§
Source§impl Value
impl Value
Sourcepub fn from_le_bytes(
bytes: &[u8],
value_type: ValueType,
) -> Result<Value, Error>
pub fn from_le_bytes( bytes: &[u8], value_type: ValueType, ) -> Result<Value, Error>
Convert a &[u8] slice to a Value. The length of the slice must match
the length of the value type, otherwise an error will be returned.
Sourcepub fn to_f64_lossy(&self) -> f64
pub fn to_f64_lossy(&self) -> f64
Sourcepub fn from_f64_lossy(value_type: ValueType, value: f64) -> Value
pub fn from_f64_lossy(value_type: ValueType, value: f64) -> Value
Make a Value from a f64 and a ValueType
This function allows to construct any type of value from a f64.
The conversion has possibility to be lossy in a couple of cases:
- When making an integer, the value is truncated to the number of bit of the parameter
- Example: Setting
257to au8variable will set it to the value1
- Example: Setting
- Similarly floating point precision will be truncated to the parameter precision. Rounding is undefined.
- Making a floating point outside the range of the parameter is undefined.
- It is not possible to represent accurately a
u64parameter in af64.