Skip to main content

Rd

Struct Rd 

Source
pub struct Rd<'a> {
    pub data: &'a [u8],
    pub what: &'static str,
}
Expand description

Bounds-checked fixed-size reads, little and big endian: every read past the end is an Error::Format that names what and the offset.

Fields§

§data: &'a [u8]

The bytes being read.

§what: &'static str

What they are, for error messages.

Implementations§

Source§

impl<'a> Rd<'a>

Source

pub fn new(data: &'a [u8], what: &'static str) -> Self

Reads over data; what names the thing being read in every error.

Source

pub fn bytes(&self, at: usize, n: usize) -> Result<&'a [u8]>

n bytes at at.

Source

pub fn arr<const N: usize>(&self, at: usize) -> Result<[u8; N]>

N bytes at at as an array.

Source

pub fn u8(&self, at: usize) -> Result<u8>

The byte at at.

Source

pub fn u16le(&self, at: usize) -> Result<u16>

The little-endian u16 at at.

Source

pub fn u32le(&self, at: usize) -> Result<u32>

The little-endian u32 at at.

Source

pub fn u64le(&self, at: usize) -> Result<u64>

The little-endian u64 at at.

Source

pub fn size32le(&self, at: usize) -> Result<usize>

The little-endian u32 at at as a size or count.

Source

pub fn offset64le(&self, at: usize) -> Result<usize>

The little-endian u64 at at as an offset or size.

Source

pub fn u32be(&self, at: usize) -> Result<u32>

The big-endian u32 at at.

Source

pub fn i32be(&self, at: usize) -> Result<i32>

The big-endian i32 at at.

Source

pub fn u64be(&self, at: usize) -> Result<u64>

The big-endian u64 at at.

Source

pub fn cstr(&self, at: usize) -> Result<String>

A zero-terminated Latin-1 string starting at at.

Trait Implementations§

Source§

impl<'a> Debug for Rd<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Rd<'a>

§

impl<'a> RefUnwindSafe for Rd<'a>

§

impl<'a> Send for Rd<'a>

§

impl<'a> Sync for Rd<'a>

§

impl<'a> Unpin for Rd<'a>

§

impl<'a> UnsafeUnpin for Rd<'a>

§

impl<'a> UnwindSafe for Rd<'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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.