Expand description
A newtype for byte slices.
It has these important features:
- no methods that can panic, such as
Index
- convenience methods for
Pod
types - a useful
Debug
implementation
Tuple Fields
0: &'data [u8]
Implementations
sourceimpl<'data> Bytes<'data>
impl<'data> Bytes<'data>
sourcepub fn skip(&mut self, offset: usize) -> Result<(), ()>
pub fn skip(&mut self, offset: usize) -> Result<(), ()>
Skip over the given number of bytes at the start of the byte slice.
Modifies the byte slice to start after the bytes.
Returns an error if there are too few bytes.
sourcepub fn read_bytes(&mut self, count: usize) -> Result<Bytes<'data>, ()>
pub fn read_bytes(&mut self, count: usize) -> Result<Bytes<'data>, ()>
Return a reference to the given number of bytes at the start of the byte slice.
Modifies the byte slice to start after the bytes.
Returns an error if there are too few bytes.
sourcepub fn read_bytes_at(
self,
offset: usize,
count: usize
) -> Result<Bytes<'data>, ()>
pub fn read_bytes_at(
self,
offset: usize,
count: usize
) -> Result<Bytes<'data>, ()>
Return a reference to the given number of bytes at the given offset of the byte slice.
Returns an error if the offset is invalid or there are too few bytes.
sourcepub fn read<T: Pod>(&mut self) -> Result<&'data T, ()>
pub fn read<T: Pod>(&mut self) -> Result<&'data T, ()>
Return a reference to a Pod
struct at the start of the byte slice.
Modifies the byte slice to start after the bytes.
Returns an error if there are too few bytes or the slice is incorrectly aligned.
sourcepub fn read_at<T: Pod>(self, offset: usize) -> Result<&'data T, ()>
pub fn read_at<T: Pod>(self, offset: usize) -> Result<&'data T, ()>
Return a reference to a Pod
struct at the given offset of the byte slice.
Returns an error if there are too few bytes or the offset is incorrectly aligned.
sourcepub fn read_slice<T: Pod>(&mut self, count: usize) -> Result<&'data [T], ()>
pub fn read_slice<T: Pod>(&mut self, count: usize) -> Result<&'data [T], ()>
Return a reference to a slice of Pod
structs at the start of the byte slice.
Modifies the byte slice to start after the bytes.
Returns an error if there are too few bytes or the offset is incorrectly aligned.
sourcepub fn read_slice_at<T: Pod>(
self,
offset: usize,
count: usize
) -> Result<&'data [T], ()>
pub fn read_slice_at<T: Pod>(
self,
offset: usize,
count: usize
) -> Result<&'data [T], ()>
Return a reference to a slice of Pod
structs at the given offset of the byte slice.
Returns an error if there are too few bytes or the offset is incorrectly aligned.
Trait Implementations
impl<'data> Copy for Bytes<'data>
impl<'data> Eq for Bytes<'data>
impl<'data> StructuralEq for Bytes<'data>
impl<'data> StructuralPartialEq for Bytes<'data>
Auto Trait Implementations
impl<'data> RefUnwindSafe for Bytes<'data>
impl<'data> Send for Bytes<'data>
impl<'data> Sync for Bytes<'data>
impl<'data> Unpin for Bytes<'data>
impl<'data> UnwindSafe for Bytes<'data>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more