pub struct LimitedReader<T> { /* private fields */ }
Available on crate feature std only.
Expand description

Encapsulated reader with an maximum allowed read length.

This struct is used to limit data reads by lower protocol layers (e.g. the payload_len in an IPv6Header limits how much data should be read by the following layers).

An crate::err::LenError is returned as soon as more than the maximum read len is read.

Implementations§

source§

impl<T: Read + Sized> LimitedReader<T>

source

pub fn new( reader: T, max_len: usize, len_source: LenSource, layer_offset: usize, layer: Layer ) -> LimitedReader<T>

Setup a new limited reader.

source

pub fn max_len(&self) -> usize

Maximum len that still can be read (on the current layer).

source

pub fn len_source(&self) -> LenSource

Source of the maximum length (used for len error).

source

pub fn layer(&self) -> Layer

Layer that is currently read (used for len error).

source

pub fn layer_offset(&self) -> usize

Offset of the layer that is currently read (used for len error).

source

pub fn read_len(&self) -> usize

Len that was read on the current layer.

source

pub fn start_layer(&mut self, layer: Layer)

Set current position as starting position for a layer.

source

pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), LimitedReadError>

Try read the given buf length from the reader.

Triggers an len error if the

source

pub fn take_reader(self) -> T

Consumes LimitedReader and returns the reader.

Trait Implementations§

source§

impl<T: Debug> Debug for LimitedReader<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for LimitedReader<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> 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>,

§

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.