Struct rustls::internal::msgs::codec::Reader

source ·
pub struct Reader<'a> {
    buffer: &'a [u8],
    cursor: usize,
}
Expand description

Wrapper over a slice of bytes that allows reading chunks from with the current position state held using a cursor.

A new reader for a sub section of the the buffer can be created using the sub function or a section of a certain length can be obtained using the take function

Fields§

§buffer: &'a [u8]

The underlying buffer storing the readers content

§cursor: usize

Stores the current reading position for the buffer

Implementations§

source§

impl<'a> Reader<'a>

source

pub fn init(bytes: &[u8]) -> Reader<'_>

Creates a new Reader of the provided bytes slice with the initial cursor position of zero.

source

pub fn sub(&mut self, length: usize) -> Result<Reader<'_>, InvalidMessage>

Attempts to create a new Reader on a sub section of this readers bytes by taking a slice of the provided length will return None if there is not enough bytes

source

pub fn rest(&mut self) -> &[u8]

Borrows a slice of all the remaining bytes that appear after the cursor position.

Moves the cursor to the end of the buffer length.

source

pub fn take(&mut self, length: usize) -> Option<&[u8]>

Attempts to borrow a slice of bytes from the current cursor position of length if there is not enough bytes remaining after the cursor to take the length then None is returned instead.

source

pub fn any_left(&self) -> bool

Used to check whether the reader has any content left after the cursor (cursor has not reached end of buffer)

source

pub fn expect_empty(&self, name: &'static str) -> Result<(), InvalidMessage>

source

pub fn used(&self) -> usize

Returns the cursor position which is also the number of bytes that have been read from the buffer.

source

pub fn left(&self) -> usize

Returns the number of bytes that are still able to be read (The number of remaining takes)

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

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.