pub struct PtrByteSlice<'a> { /* private fields */ }Expand description
A read-only view of a raw pointer byte slice, providing a safe API.
Implementations§
Source§impl<'a> PtrByteSlice<'a>
impl<'a> PtrByteSlice<'a>
Sourcepub unsafe fn new(slice: *const [u8]) -> Self
pub unsafe fn new(slice: *const [u8]) -> Self
Creates a new PtrByteSlice from a raw pointer to a byte slice.
§Safety
The caller must ensure that slice is valid for reads for the lifetime 'a.
Sourcepub fn read<T: Copy + FromBytes>(&self) -> Option<T>
pub fn read<T: Copy + FromBytes>(&self) -> Option<T>
Reads a copy of a value of type T from the start of the slice.
The read is performed unaligned, so the slice does not need to be aligned to T.
Sourcepub fn copy_to_slice(&self, dest: &mut [u8])
pub fn copy_to_slice(&self, dest: &mut [u8])
Copies the contents of this slice into a safe Rust mutable slice.
§Panics
Panics if dest is smaller than self.len().
Sourcepub fn as_raw_slice_ptr(&self) -> *const [u8]
pub fn as_raw_slice_ptr(&self) -> *const [u8]
Returns the raw pointer to the slice.
Sourcepub fn to_vec(&self) -> Vec<u8> ⓘ
pub fn to_vec(&self) -> Vec<u8> ⓘ
Allocates a new heap Vector and copies the contents into it. Bypasses zero-initialization using raw pointer copies.
Trait Implementations§
Source§impl<'a> Clone for PtrByteSlice<'a>
impl<'a> Clone for PtrByteSlice<'a>
impl<'a> Copy for PtrByteSlice<'a>
Source§impl<'a> Debug for PtrByteSlice<'a>
impl<'a> Debug for PtrByteSlice<'a>
Source§impl<'a> From<&'a [u8]> for PtrByteSlice<'a>
impl<'a> From<&'a [u8]> for PtrByteSlice<'a>
Source§impl<'a> From<MutPtrByteSlice<'a>> for PtrByteSlice<'a>
impl<'a> From<MutPtrByteSlice<'a>> for PtrByteSlice<'a>
Source§fn from(slice: MutPtrByteSlice<'a>) -> Self
fn from(slice: MutPtrByteSlice<'a>) -> Self
Converts to this type from the input type.
Source§impl Read for PtrByteSlice<'_>
impl Read for PtrByteSlice<'_>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Reads the exact number of bytes required to fill
buf. Read moreSource§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
Reads all bytes until EOF in this source, placing them into
buf. Read more1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Reads the exact number of bytes required to fill
cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adapter for this instance of
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
Creates an adapter which will read at most
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
🔬This is a nightly-only experimental API. (
read_array)Read and return a fixed array of bytes from this source. Read more
impl Send for PtrByteSlice<'_>
impl Sync for PtrByteSlice<'_>
Auto Trait Implementations§
impl<'a> Freeze for PtrByteSlice<'a>
impl<'a> RefUnwindSafe for PtrByteSlice<'a>
impl<'a> Unpin for PtrByteSlice<'a>
impl<'a> UnsafeUnpin for PtrByteSlice<'a>
impl<'a> UnwindSafe for PtrByteSlice<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more