pub struct Modes<const N: usize> { /* private fields */ }Expand description
A canonical packet of ordered mode values.
N is the maximum number of modes and must be greater than zero.
The high bit indicates that another mode follows, and trailing zero-valued
modes are omitted. Appending a new mode with value zero therefore preserves
the existing encoding. A Modes value denotes a present packet. An all-zero
list denotes no packet.
§Examples
use commonware_codec::{DecodeExt, Encode, Modes, mode};
let modes = Modes::new([mode!(1), mode!(0), mode!(2)]).unwrap();
let encoded = modes.encode();
assert_eq!(encoded.as_ref(), &[0x81, 0x80, 0x02]);
assert_eq!(Modes::<3>::decode(encoded).unwrap(), modes);ⓘ
use commonware_codec::Modes;
let _ = Modes::<0>::new([]);Implementations§
Trait Implementations§
impl<const N: usize> Copy for Modes<N>
Source§impl<const N: usize> EncodeSize for Modes<N>
impl<const N: usize> EncodeSize for Modes<N>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Returns the encoded size of this value (in bytes).
Source§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
Returns the encoded size excluding bytes passed to
BufsMut::push
during Write::write_bufs. Used to size the working buffer for inline
writes. Override alongside Write::write_bufs for types where large
Bytes fields go via push; failing to do so will over-allocate.impl<const N: usize> Eq for Modes<N>
Source§impl<const N: usize> Read for Modes<N>
impl<const N: usize> Read for Modes<N>
impl<const N: usize> StructuralPartialEq for Modes<N>
Source§impl<const N: usize> Write for Modes<N>
impl<const N: usize> Write for Modes<N>
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
Writes to a
BufsMut, allowing existing Bytes chunks to be
appended via BufsMut::push instead of written inline. Must encode
to the same format as Write::write. Defaults to Write::write.Auto Trait Implementations§
impl<const N: usize> Freeze for Modes<N>
impl<const N: usize> RefUnwindSafe for Modes<N>
impl<const N: usize> Send for Modes<N>
impl<const N: usize> Sync for Modes<N>
impl<const N: usize> Unpin for Modes<N>
impl<const N: usize> UnsafeUnpin for Modes<N>
impl<const N: usize> UnwindSafe for Modes<N>
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