Skip to main content

WireLen

Enum WireLen 

Source
pub enum WireLen<T> {
    Auto,
    Set(T),
}
Expand description

A wire length/count field: Auto-derived by default, or an explicit Set override. See the module docs.

Variants§

§

Auto

Derive this length from its declared target when the message is encoded.

§

Set(T)

Write exactly this value — a deliberate override, or the value read on decode.

Implementations§

Source§

impl<T> WireLen<T>

Source

pub fn auto() -> Self

An auto-deriving length (the default). Equivalent to WireLen::Auto.

Source

pub fn set(value: T) -> Self

A pinned, explicit length. Equivalent to WireLen::Set — the dual-use override.

Source

pub fn is_auto(&self) -> bool

Whether this length auto-derives (has no explicit value yet).

Source

pub fn get(&self) -> Option<&T>

The explicit value, or None if it auto-derives. A decoded WireLen is always Some; a freshly-built Auto is None until resolved at encode.

Source§

impl<T: CountPrefix> WireLen<T>

Source

pub fn to_count(&self) -> usize

The value as a usize element count (for #[br(count = …)] on the decode side, where a WireLen is always Set). An unresolved Auto reads as 0 (it never occurs on decode).

Source

pub fn resolve_count(&self, len: usize) -> Result<Self, BitError>

Resolve an Auto to the checked count of len (leaving a Set untouched) — the encode-time derivation the macro emits.

§Errors

BitError if len exceeds T’s range (a checked conversion, never a truncation).

Trait Implementations§

Source§

impl<T: Bits> BitDecode for WireLen<T>

Source§

fn bit_decode<S: Source>(r: &mut S) -> Result<Self, BitError>

Decodes Self from any Source, advancing its cursor. Read more
Source§

impl<T: Bits> BitEncode for WireLen<T>

Source§

fn bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError>

Encodes self verbatim into any Sink, advancing its cursor. Read more
Source§

const LAYOUT: Layout = _

The message’s bit/byte order, used to size a fresh BitWriter when encoding to a Vec/writer. The derive sets it from the struct’s declared bit_order/bytes; a hand-written impl that only ever encodes into a caller-supplied Sink can leave the default.
Source§

fn canonical_bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError>

Encodes self’s canonical form into any Sink: reserved fields as their spec value, calc fields recomputed. Defaults to bit_encode (verbatim == canonical) for messages with no reserved/calc field. Read more
Source§

impl<T: Clone> Clone for WireLen<T>

Source§

fn clone(&self) -> WireLen<T>

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<T: Copy> Copy for WireLen<T>

Source§

impl<T: Debug> Debug for WireLen<T>

Source§

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

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

impl<T> Default for WireLen<T>

Source§

fn default() -> WireLen<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Eq> Eq for WireLen<T>

Source§

impl<T: Bits> FixedBitLen for WireLen<T>

A WireLen<T> occupies exactly T’s width, so it stays a fixed-width field (a DNS header with WireLen<u16> counts is still 12 bytes).

Source§

const BIT_LEN: u32 = <T as Bits>::BITS

Total encoded width of the message in bits — the sum of its fields’ widths.
Source§

impl<T: Hash> Hash for WireLen<T>

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<T: PartialEq> PartialEq for WireLen<T>

Source§

fn eq(&self, other: &WireLen<T>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for WireLen<T>

Auto Trait Implementations§

§

impl<T> Freeze for WireLen<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for WireLen<T>
where T: RefUnwindSafe,

§

impl<T> Send for WireLen<T>
where T: Send,

§

impl<T> Sync for WireLen<T>
where T: Sync,

§

impl<T> Unpin for WireLen<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for WireLen<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for WireLen<T>
where T: 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> DecodeWith<()> for T
where T: BitDecode,

Source§

fn decode_with<S>(r: &mut S, _args: ()) -> Result<T, BitError>
where S: Source,

Decodes Self from a Source given args. Read more
Source§

impl<T> EncodeExt for T
where T: BitEncode,

Source§

fn encode<W: Write>(&self, w: &mut W) -> Result<(), BitError>
where Self: Sized,

Available on crate feature std only.
Encodes self verbatim to any std::io::Write (socket, file, Vec) — exactly what’s stored. For the canonical form, encode self.to_canonical().encode(&mut w), or use the inherent to_bytes (verbatim) / to_canonical_bytes (canonical) instead. Read more
Source§

impl<T> EncodeWith<()> for T
where T: BitEncode,

Source§

fn encode_with<K>(&self, w: &mut K, _args: ()) -> Result<(), BitError>
where K: Sink,

Encodes self into a Sink given args. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more