Struct Slice

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

An owned view into a contiguous sequence of bytes. Slice implements IoBuf.

Implementations§

Source§

impl<T: IoBuf> Slice<T>

Source

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

Create a Slice from a buffer and range.

Source§

impl<T> Slice<T>

Source

pub const unsafe fn new_unchecked(buf: T, begin: usize, end: usize) -> Self

Create a Slice from a buffer and range without boundary checking.

§Safety

begin and end must be within the buffer initialized range.

Source

pub const fn begin(&self) -> usize

Offset in the underlying buffer at which this slice starts.

Source

pub const fn end(&self) -> usize

Ofset in the underlying buffer at which this slice ends.

Source

pub const fn get_ref(&self) -> &T

Gets a reference to the underlying buffer.

Source

pub fn get_mut(&mut self) -> &mut T

Gets a mutable reference to the underlying buffer.

Source

pub fn into_inner(self) -> T

Unwraps this Slice, returning the underlying buffer.

Trait Implementations§

Source§

impl<T: IoBuf> IoBuf for Slice<T>

Source§

fn read_ptr(&self) -> *const u8

Returns a raw pointer to the vector’s buffer. Read more
Source§

fn bytes_init(&self) -> usize

Number of initialized bytes. Read more
Source§

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

Returns a slice of the buffer.
Source§

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

Returns a view of the buffer with the specified range.
Source§

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

Returns a view of the buffer with the specified range without boundary checking. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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.