Skip to main content

ReadBuf

Struct ReadBuf 

Source
pub struct ReadBuf<'a> { /* private fields */ }
Expand description

A buffer being filled by reads: its first filled bytes hold data, its first initialized bytes are initialized (filled <= initialized), and the rest may be uninitialized memory that a read may write into.

Implementations§

Source§

impl<'a> ReadBuf<'a>

Source

pub fn new(buf: &'a mut [u8]) -> Self

A buffer over buf, all of it initialized, none of it filled.

Source

pub fn uninit(buf: &'a mut [MaybeUninit<u8>]) -> Self

A buffer over buf, none of it initialized or filled.

Source

pub fn capacity(&self) -> usize

The buffer’s whole length.

Source

pub fn filled(&self) -> &[u8] ⓘ

The bytes filled so far.

Source

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

The bytes filled so far, to change.

Source

pub fn initialized(&self) -> &[u8] ⓘ

The bytes known to be initialized, filled or not.

Source

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

The bytes known to be initialized, to change.

Source

pub fn take(&mut self, n: usize) -> ReadBuf<'_>

A buffer over at most n bytes of the unfilled part, sharing what is known to be initialized there.

Source

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

Initializes the whole unfilled part (zeroing what was not initialized) and answers it, for a read to write into.

Source

pub fn initialize_unfilled_to(&mut self, n: usize) -> &mut [u8] ⓘ

Initializes the first n bytes of the unfilled part and answers them.

§Panics

When n is more than remaining.

Source

pub fn remaining(&self) -> usize

The room left after the filled part.

Source

pub fn clear(&mut self)

Empties the filled part; what was initialized stays initialized.

Source

pub fn advance(&mut self, n: usize)

Counts n more bytes as filled.

§Panics

When that passes the initialized part.

Source

pub fn set_filled(&mut self, n: usize)

Sets how many bytes are filled.

§Panics

When n passes the initialized part.

Source

pub unsafe fn assume_init(&mut self, n: usize)

Counts the first n bytes of the unfilled part as initialized.

§Safety

The caller has initialized those bytes.

Source

pub fn put_slice(&mut self, bytes: &[u8])

Appends bytes to the filled part.

§Panics

When they do not fit in remaining.

Source

pub unsafe fn unfilled_mut(&mut self) -> &mut [MaybeUninit<u8>]

The unfilled part, as memory that may be uninitialized.

§Safety

The caller must not write uninitialized bytes into it: the part known to be initialized must stay initialized.

Trait Implementations§

Source§

impl Debug for ReadBuf<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ReadBuf<'a>

§

impl<'a> Freeze for ReadBuf<'a>

§

impl<'a> RefUnwindSafe for ReadBuf<'a>

§

impl<'a> Send for ReadBuf<'a>

§

impl<'a> Sync for ReadBuf<'a>

§

impl<'a> Unpin for ReadBuf<'a>

§

impl<'a> UnsafeUnpin for ReadBuf<'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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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.