add ability to convert unsigned enum to Vec

This commit is contained in:
Robin Müller 2024-02-17 00:00:07 +01:00
parent f47604346e
commit 8c23a9c924
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -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 {}