pub struct Bytes<'data>(pub &'data [u8]);
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§
source§impl<'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.
sourcepub fn read_string(&mut self) -> Result<&'data [u8], ()>
pub fn read_string(&mut self) -> Result<&'data [u8], ()>
Read a null terminated string.
Does not assume any encoding. Reads past the null byte, but doesn’t return it.
sourcepub fn read_string_at(self, offset: usize) -> Result<&'data [u8], ()>
pub fn read_string_at(self, offset: usize) -> Result<&'data [u8], ()>
Read a null terminated string at an offset.
Does not assume any encoding. Does not return the null byte.
sourcepub fn read_uleb128(&mut self) -> Result<u64, ()>
pub fn read_uleb128(&mut self) -> Result<u64, ()>
Read an unsigned LEB128 number.
sourcepub fn read_sleb128(&mut self) -> Result<i64, ()>
pub fn read_sleb128(&mut self) -> Result<i64, ()>
Read a signed LEB128 number.
Trait Implementations§
impl<'data> Copy for Bytes<'data>
impl<'data> Eq for Bytes<'data>
impl<'data> StructuralPartialEq for Bytes<'data>
Auto Trait Implementations§
impl<'data> Freeze for Bytes<'data>
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§
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)