Skip to main content

Measured

Struct Measured 

pub struct Measured<'a, B: ?Sized> {
    body: &'a B,
    remaining: Vbi,
    len: usize,
}
Expand description

A packet whose Remaining Length fits in a Variable Byte Integer.

Measuring is the only step that can find a packet too large. Encoding a measured packet fails only if the sink does.

Fields§

§body: &'a B§remaining: Vbi§len: usize

Implementations§

§

impl<'a, B: Body + ?Sized> Measured<'a, B>

pub fn new(body: &'a B) -> Option<Self>

Measures body. Returns None if its length exceeds the Variable Byte Integer maximum (Vbi::MAX_USIZE, about 256 MiB).

pub const fn encoded_len(&self) -> usize

Returns the encoded length of the whole packet, fixed header included.

pub fn encode<S: Sink>(&self, sink: S) -> Result<(), S::Error>

Writes the whole packet, fixed header included.

§Errors

Returns the sink’s error if it cannot take the bytes.

Trait Implementations§

§

impl<'a, B: Debug + ?Sized> Debug for Measured<'a, B>

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, B> Freeze for Measured<'a, B>
where &'a B: Freeze, B: ?Sized,

§

impl<'a, B> RefUnwindSafe for Measured<'a, B>

§

impl<'a, B> Send for Measured<'a, B>
where &'a B: Send, B: ?Sized,

§

impl<'a, B> Sync for Measured<'a, B>
where &'a B: Sync, B: ?Sized,

§

impl<'a, B> Unpin for Measured<'a, B>
where &'a B: Unpin, B: ?Sized,

§

impl<'a, B> UnsafeUnpin for Measured<'a, B>
where &'a B: UnsafeUnpin, B: ?Sized,

§

impl<'a, B> UnwindSafe for Measured<'a, B>
where &'a B: UnwindSafe, B: ?Sized,

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> 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, 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, <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.