Skip to main content

Modes

Struct Modes 

Source
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§

Source§

impl<const N: usize> Modes<N>

Source

pub fn new(modes: [Mode; N]) -> Option<Self>

Creates a canonical packet from modes.

Returns None when every mode is zero. Callers must represent this as an absent packet rather than an empty packet.

Trait Implementations§

Source§

impl<const N: usize> Clone for Modes<N>

Source§

fn clone(&self) -> Modes<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for Modes<N>

Source§

impl<const N: usize> Debug for Modes<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> EncodeSize for Modes<N>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

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.
Source§

impl<const N: usize> Eq for Modes<N>

Source§

impl<const N: usize> Hash for Modes<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> PartialEq for Modes<N>

Source§

fn eq(&self, other: &Modes<N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> Read for Modes<N>

Source§

type Cfg = ()

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<const N: usize> StructuralPartialEq for Modes<N>

Source§

impl<const N: usize> Write for Modes<N>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

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>
where [u8; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for Modes<N>
where [u8; N]: RefUnwindSafe,

§

impl<const N: usize> Send for Modes<N>
where [u8; N]: Send,

§

impl<const N: usize> Sync for Modes<N>
where [u8; N]: Sync,

§

impl<const N: usize> Unpin for Modes<N>
where [u8; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for Modes<N>
where [u8; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for Modes<N>
where [u8; N]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Codec for T
where T: Encode + Decode,

Source§

impl<T> CodecShared for T
where T: Codec + Send + Sync,

Source§

impl<T> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<X, T> DecodeExt<X> for T
where X: IsUnit, T: Decode<Cfg = X>,

Source§

fn decode(buf: impl Buf) -> Result<Self, Error>

Decodes a value using the default () config.
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> Bytes

Encodes self into a new Bytes buffer. Read more
Source§

fn encode_mut(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
Source§

impl<T> EncodeShared for T
where T: Encode + Send + Sync,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReadExt for T
where T: Read<Cfg = ()>,

Source§

fn read(buf: &mut impl Buf) -> Result<Self, Error>

Reads a value using the default () config.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.