[][src]Struct object::pod::Bytes

pub struct Bytes<'data>(pub &'data [u8]);

A newtype for byte slices.

It has these important features:

Implementations

impl<'data> Bytes<'data>[src]

pub fn len(&self) -> usize[src]

Return the length of the byte slice.

pub fn is_empty(&self) -> bool[src]

Return true if the byte slice is empty.

pub fn skip(&mut self, offset: usize) -> Result<(), ()>[src]

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.

pub fn read_bytes(&mut self, count: usize) -> Result<Bytes<'data>, ()>[src]

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.

pub fn read_bytes_at(
    self,
    offset: usize,
    count: usize
) -> Result<Bytes<'data>, ()>
[src]

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.

pub fn read<T: Pod>(&mut self) -> Result<&'data T, ()>[src]

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.

pub fn read_at<T: Pod>(self, offset: usize) -> Result<&'data T, ()>[src]

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.

pub fn read_slice<T: Pod>(&mut self, count: usize) -> Result<&'data [T], ()>[src]

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.

pub fn read_slice_at<T: Pod>(
    self,
    offset: usize,
    count: usize
) -> Result<&'data [T], ()>
[src]

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.

pub fn read_string(&mut self) -> Result<&'data [u8], ()>[src]

Read a null terminated string.

Does not assume any encoding. Reads past the null byte, but doesn't return it.

pub fn read_string_at(self, offset: usize) -> Result<&'data [u8], ()>[src]

Read a null terminated string at an offset.

Does not assume any encoding. Does not return the null byte.

Trait Implementations

impl<'data> Clone for Bytes<'data>[src]

impl<'data> Copy for Bytes<'data>[src]

impl<'data> Debug for Bytes<'data>[src]

impl<'data> Default for Bytes<'data>[src]

impl<'data> Eq for Bytes<'data>[src]

impl<'data> PartialEq<Bytes<'data>> for Bytes<'data>[src]

impl<'data> StructuralEq for Bytes<'data>[src]

impl<'data> StructuralPartialEq for Bytes<'data>[src]

Auto Trait Implementations

impl<'data> Send for Bytes<'data>

impl<'data> Sync for Bytes<'data>

impl<'data> Unpin for Bytes<'data>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.