Skip to main content

Slice

Struct Slice 

Source
pub struct Slice<B> { /* private fields */ }
Expand description

A bounded view into an owned IoBuf or IoBufMut buffer.

Allows passing a subset of a buffer to an I/O operation without splitting or consuming it. The original buffer is reclaimed via into_inner after the operation completes.

Implementations§

Source§

impl<B: IoBuf> Slice<B>

Source

pub fn new(buf: B, begin: usize, end: usize) -> Self

Creates a new slice into buf bounded by [begin, end).

§Panics

Panics if begin > end or end > buf.bytes_total().

Source

pub fn into_inner(self) -> B

Consumes the slice and returns the underlying buffer.

Source

pub fn len(&self) -> usize

Returns the length of initialized bytes of this slice.

Source

pub fn is_empty(&self) -> bool

Returns true if the length of this slice is zero.

Trait Implementations§

Source§

impl<B: IoBuf> AsRef<[u8]> for Slice<B>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<B: Debug> Debug for Slice<B>

Source§

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

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

impl<B: IoBuf> IoBuf for Slice<B>

Source§

fn stable_ptr(&self) -> *const u8

Returns a stable pointer to the start of the initialized data.
Source§

fn bytes_init(&self) -> usize

Number of initialized bytes, valid to read.
Source§

fn bytes_total(&self) -> usize

Total capacity, including uninitialized memory. This is what gets passed to the kernel for reads.
Source§

fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
where Self: Sized,

Returns a bounded view into this buffer.
Source§

impl<B: IoBufMut> IoBufMut for Slice<B>

Source§

fn stable_mut_ptr(&mut self) -> *mut u8

Returns a stable mutable pointer to the start of the buffer.
Source§

unsafe fn set_init(&mut self, pos: usize)

Mark the first pos bytes as initialized. Read more
Source§

fn clear(&mut self)

Clear this buffer, setting the initialized bytes to 0.

Auto Trait Implementations§

§

impl<B> Freeze for Slice<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Slice<B>
where B: RefUnwindSafe,

§

impl<B> Send for Slice<B>
where B: Send,

§

impl<B> Sync for Slice<B>
where B: Sync,

§

impl<B> Unpin for Slice<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Slice<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for Slice<B>
where B: 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>,

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.