Struct Bytes

Source
pub struct Bytes<'a> { /* private fields */ }
Expand description

A slice wrapper that implements BytesRead.

Implementations§

Source§

impl<'a> Bytes<'a>

Source

pub fn new(position: usize, inner: &'a [u8]) -> Self

You should probably use:

let bytes: Bytes = slice.into();
// or
let bytes = Bytes::from(slice);
Source

pub fn inner(&self) -> &'a [u8]

Returns the inner slice with the original reference.

Trait Implementations§

Source§

impl BytesRead for Bytes<'_>

Source§

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

Returns the entire slice.
Source§

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

Returns all remaining bytes.
Source§

fn try_read(&mut self, len: usize) -> Result<&[u8], ReadError>

Try to read a given length of bytes. Read more
Source§

fn peek(&self, len: usize) -> Option<&[u8]>

Tries to read a given length without updating the internal position. Returns None if there are not enought bytes remaining.
Source§

fn len(&self) -> usize

Returns the length of the entire slice.
Source§

fn read(&mut self, len: usize) -> &[u8]

Reads a given length of bytes. Read more
Source§

fn try_read_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in big-endian converting them into an u8.
Source§

fn read_u8(&mut self) -> u8

Reads 1 bytes in big-endian converting them into an u8. Read more
Source§

fn try_read_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in big-endian converting them into an u16.
Source§

fn read_u16(&mut self) -> u16

Reads 2 bytes in big-endian converting them into an u16. Read more
Source§

fn try_read_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in big-endian converting them into an u32.
Source§

fn read_u32(&mut self) -> u32

Reads 4 bytes in big-endian converting them into an u32. Read more
Source§

fn try_read_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in big-endian converting them into an u64.
Source§

fn read_u64(&mut self) -> u64

Reads 8 bytes in big-endian converting them into an u64. Read more
Source§

fn try_read_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in big-endian converting them into an u128.
Source§

fn read_u128(&mut self) -> u128

Reads 16 bytes in big-endian converting them into an u128. Read more
Source§

fn try_read_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in big-endian converting them into an i8.
Source§

fn read_i8(&mut self) -> i8

Reads 1 bytes in big-endian converting them into an i8. Read more
Source§

fn try_read_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in big-endian converting them into an i16.
Source§

fn read_i16(&mut self) -> i16

Reads 2 bytes in big-endian converting them into an i16. Read more
Source§

fn try_read_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in big-endian converting them into an i32.
Source§

fn read_i32(&mut self) -> i32

Reads 4 bytes in big-endian converting them into an i32. Read more
Source§

fn try_read_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in big-endian converting them into an i64.
Source§

fn read_i64(&mut self) -> i64

Reads 8 bytes in big-endian converting them into an i64. Read more
Source§

fn try_read_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in big-endian converting them into an i128.
Source§

fn read_i128(&mut self) -> i128

Reads 16 bytes in big-endian converting them into an i128. Read more
Source§

fn try_read_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in big-endian converting them into an f32.
Source§

fn read_f32(&mut self) -> f32

Reads 4 bytes in big-endian converting them into an f32. Read more
Source§

fn try_read_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in big-endian converting them into an f64.
Source§

fn read_f64(&mut self) -> f64

Reads 8 bytes in big-endian converting them into an f64. Read more
Source§

fn try_read_le_u8(&mut self) -> Result<u8, ReadError>

Try to read 1 bytes in little-endian converting them into an u8.
Source§

fn read_le_u8(&mut self) -> u8

Reads 1 bytes in little-endian converting them into an u8. Read more
Source§

fn try_read_le_u16(&mut self) -> Result<u16, ReadError>

Try to read 2 bytes in little-endian converting them into an u16.
Source§

fn read_le_u16(&mut self) -> u16

Reads 2 bytes in little-endian converting them into an u16. Read more
Source§

fn try_read_le_u32(&mut self) -> Result<u32, ReadError>

Try to read 4 bytes in little-endian converting them into an u32.
Source§

fn read_le_u32(&mut self) -> u32

Reads 4 bytes in little-endian converting them into an u32. Read more
Source§

fn try_read_le_u64(&mut self) -> Result<u64, ReadError>

Try to read 8 bytes in little-endian converting them into an u64.
Source§

fn read_le_u64(&mut self) -> u64

Reads 8 bytes in little-endian converting them into an u64. Read more
Source§

fn try_read_le_u128(&mut self) -> Result<u128, ReadError>

Try to read 16 bytes in little-endian converting them into an u128.
Source§

fn read_le_u128(&mut self) -> u128

Reads 16 bytes in little-endian converting them into an u128. Read more
Source§

fn try_read_le_i8(&mut self) -> Result<i8, ReadError>

Try to read 1 bytes in little-endian converting them into an i8.
Source§

fn read_le_i8(&mut self) -> i8

Reads 1 bytes in little-endian converting them into an i8. Read more
Source§

fn try_read_le_i16(&mut self) -> Result<i16, ReadError>

Try to read 2 bytes in little-endian converting them into an i16.
Source§

fn read_le_i16(&mut self) -> i16

Reads 2 bytes in little-endian converting them into an i16. Read more
Source§

fn try_read_le_i32(&mut self) -> Result<i32, ReadError>

Try to read 4 bytes in little-endian converting them into an i32.
Source§

fn read_le_i32(&mut self) -> i32

Reads 4 bytes in little-endian converting them into an i32. Read more
Source§

fn try_read_le_i64(&mut self) -> Result<i64, ReadError>

Try to read 8 bytes in little-endian converting them into an i64.
Source§

fn read_le_i64(&mut self) -> i64

Reads 8 bytes in little-endian converting them into an i64. Read more
Source§

fn try_read_le_i128(&mut self) -> Result<i128, ReadError>

Try to read 16 bytes in little-endian converting them into an i128.
Source§

fn read_le_i128(&mut self) -> i128

Reads 16 bytes in little-endian converting them into an i128. Read more
Source§

fn try_read_le_f32(&mut self) -> Result<f32, ReadError>

Try to read 4 bytes in little-endian converting them into an f32.
Source§

fn read_le_f32(&mut self) -> f32

Reads 4 bytes in little-endian converting them into an f32. Read more
Source§

fn try_read_le_f64(&mut self) -> Result<f64, ReadError>

Try to read 8 bytes in little-endian converting them into an f64.
Source§

fn read_le_f64(&mut self) -> f64

Reads 8 bytes in little-endian converting them into an f64. Read more
Source§

impl<'a> BytesReadRef<'a> for Bytes<'a>

Source§

fn as_slice_ref(&self) -> &'a [u8]

Returns the entire slice.
Source§

fn remaining_ref(&self) -> &'a [u8]

Returns all remaining bytes.
Source§

fn try_read_ref(&mut self, len: usize) -> Result<&'a [u8], ReadError>

Try to read a given length of bytes. Read more
Source§

fn peek_ref(&self, len: usize) -> Option<&'a [u8]>

Tries to read a given length without updating the internal position. Returns None if there are not enought bytes remaining.
Source§

fn read_ref(&mut self, len: usize) -> &'a [u8]

Reads a given length of bytes. Read more
Source§

impl BytesSeek for Bytes<'_>

Source§

fn position(&self) -> usize

Returns the internal position.

Source§

fn try_seek(&mut self, pos: usize) -> Result<(), SeekError>

Sets the internal position.

§Fails

If the position exceeds the slice.

Source§

fn seek(&mut self, pos: usize)

Sets the internal position.
Source§

fn try_advance(&mut self, adv: usize) -> Result<(), SeekError>

Advances the internal position if possible.
Source§

fn advance(&mut self, adv: usize)

Advances the internal position. Read more
Source§

impl<'a> Clone for Bytes<'a>

Source§

fn clone(&self) -> Bytes<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Bytes<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a [u8]> for Bytes<'a>

Source§

fn from(s: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for Bytes<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Bytes<'a>

Source§

fn eq(&self, other: &Bytes<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Read for Bytes<'_>

Source§

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
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

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 more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> 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<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

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,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl Seek for Bytes<'_>

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more
Source§

impl<'a> Copy for Bytes<'a>

Source§

impl<'a> Eq for Bytes<'a>

Source§

impl<'a> StructuralPartialEq for Bytes<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Bytes<'a>

§

impl<'a> RefUnwindSafe for Bytes<'a>

§

impl<'a> Send for Bytes<'a>

§

impl<'a> Sync for Bytes<'a>

§

impl<'a> Unpin for Bytes<'a>

§

impl<'a> UnwindSafe for Bytes<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.