pub struct PacketConstraints { /* private fields */ }
Expand description

The constraints required by a PacketBuilder.

PacketConstraints represents the constraints that must be satisfied in order to serialize a PacketBuilder.

A PacketConstraints, c, guarantees two properties:

  • c.max_body_len() >= c.min_body_len()
  • c.header_len() + c.min_body_len() + c.footer_len() does not overflow usize

It is not possible (using safe code) to obtain a PacketConstraints which violates these properties, so code may rely for its correctness on the assumption that these properties hold.

Implementations§

source§

impl PacketConstraints

source

pub const UNCONSTRAINED: Self = _

A no-op PacketConstraints which does not add any constraints - there is no header, footer, minimum body length requirement, or maximum body length requirement.

source

pub fn new( header_len: usize, footer_len: usize, min_body_len: usize, max_body_len: usize ) -> PacketConstraints

Constructs a new PacketConstraints.

§Panics

new panics if the arguments violate the validity properties of PacketConstraints - if max_body_len < min_body_len, or if header_len + min_body_len + footer_len overflows usize.

source

pub fn try_new( header_len: usize, footer_len: usize, min_body_len: usize, max_body_len: usize ) -> Option<PacketConstraints>

Tries to construct a new PacketConstraints.

new returns None if the provided values violate the validity properties of PacketConstraints - if max_body_len < min_body_len, or if header_len + min_body_len + footer_len overflows usize.

source

pub fn with_max_body_len(max_body_len: usize) -> PacketConstraints

Constructs a new PacketConstraints with a given max_body_len.

The header_len, footer_len, and min_body_len are all 0.

source

pub fn header_len(&self) -> usize

The number of bytes in this packet’s header.

source

pub fn footer_len(&self) -> usize

The number of bytes in this packet’s footer.

source

pub fn min_body_len(&self) -> usize

The minimum body length (in bytes) required by this packet in order to avoid adding padding.

min_body_len returns the minimum number of body bytes required in order to avoid adding padding. Note that, if padding bytes are required, they may not necessarily belong immediately following the body, depending on which packet layer imposes the minimum. In particular, in a nested packet, padding goes after the body of the layer which imposes the minimum. This means that, if the layer that imposes the minimum is not the innermost one, then padding must be added not after the innermost body, but instead in between footers. [NestedPacketBuilder::serialize_into] is responsible for inserting padding when serializing nested packets.

If there is no minimum body length, this returns 0.

source

pub fn max_body_len(&self) -> usize

The maximum length (in bytes) of a body allowed by this packet.

If there is no maximum body length, this returns core::usize::MAX.

source

pub fn try_encapsulate(&self, outer: &Self) -> Option<PacketConstraints>

Attempts to encapsulate self in outer.

Upon success, try_encapsulate returns a PacketConstraints which represents the encapsulation of self in outer. Its header length, footer length, minimum body length, and maximum body length are set accordingly.

This is probably not the method you want to use; consider Serializer::encapsulate instead.

Trait Implementations§

source§

impl Clone for PacketConstraints

source§

fn clone(&self) -> PacketConstraints

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for PacketConstraints

source§

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

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

impl PartialEq for PacketConstraints

source§

fn eq(&self, other: &PacketConstraints) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for PacketConstraints

source§

impl Eq for PacketConstraints

source§

impl StructuralPartialEq for PacketConstraints

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.