add ability to convert unsigned enum to Vec
This commit is contained in:
parent
f47604346e
commit
8c23a9c924
@ -73,6 +73,13 @@ pub trait UnsignedEnum {
|
||||
fn size(&self) -> usize;
|
||||
/// Write the unsigned enumeration to a raw buffer. Returns the written size on success.
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError>;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
fn to_vec(&self) -> alloc::vec::Vec<u8> {
|
||||
let mut buf = alloc::vec![0; self.size()];
|
||||
self.write_to_be_bytes(&mut buf).unwrap();
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
pub trait UnsignedEnumExt: UnsignedEnum + Debug + Copy + Clone + PartialEq + Eq {}
|
||||
|
Loading…
Reference in New Issue
Block a user