these conversions are also useful
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
This commit is contained in:
parent
ea05a547ac
commit
77862868d5
@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
## Added
|
||||
|
||||
- `From<$EcssEnum$TY> from $TY` for the ECSS enum type definitions.
|
||||
|
||||
# [v0.11.0-rc.0] 2024-03-04
|
||||
|
||||
## Added
|
||||
|
@ -370,6 +370,12 @@ macro_rules! generic_ecss_enum_typedefs_and_from_impls {
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$Enum> for $ty {
|
||||
fn from(value: $Enum) -> Self {
|
||||
value.value_typed()
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
@ -424,6 +430,8 @@ mod tests {
|
||||
assert_eq!(buf[1], 1);
|
||||
assert_eq!(my_enum.value(), 1);
|
||||
assert_eq!(my_enum.value_typed(), 1);
|
||||
let enum_as_u8: u8 = my_enum.into();
|
||||
assert_eq!(enum_as_u8, 1);
|
||||
let vec = my_enum.to_vec();
|
||||
assert_eq!(vec, buf[1..2]);
|
||||
}
|
||||
@ -441,6 +449,8 @@ mod tests {
|
||||
assert_eq!(buf[2], 0x2f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f);
|
||||
let enum_as_raw: u16 = my_enum.into();
|
||||
assert_eq!(enum_as_raw, 0x1f2f);
|
||||
let vec = my_enum.to_vec();
|
||||
assert_eq!(vec, buf[1..3]);
|
||||
}
|
||||
@ -476,6 +486,8 @@ mod tests {
|
||||
assert_eq!(buf[4], 0x4f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f3f4f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f3f4f);
|
||||
let enum_as_raw: u32 = my_enum.into();
|
||||
assert_eq!(enum_as_raw, 0x1f2f3f4f);
|
||||
let vec = my_enum.to_vec();
|
||||
assert_eq!(vec, buf[1..5]);
|
||||
}
|
||||
@ -512,6 +524,8 @@ mod tests {
|
||||
assert_eq!(buf[7], 0x5f);
|
||||
assert_eq!(my_enum.value(), 0x1f2f3f4f5f);
|
||||
assert_eq!(my_enum.value_typed(), 0x1f2f3f4f5f);
|
||||
let enum_as_raw: u64 = my_enum.into();
|
||||
assert_eq!(enum_as_raw, 0x1f2f3f4f5f);
|
||||
assert_eq!(u64::from_be_bytes(buf), 0x1f2f3f4f5f);
|
||||
let vec = my_enum.to_vec();
|
||||
assert_eq!(vec, buf);
|
||||
|
Loading…
Reference in New Issue
Block a user