Skip to main content

SharedAlignedBufferReader

Struct SharedAlignedBufferReader 

Source
pub struct SharedAlignedBufferReader<'a, A>
where A: Alignment,
{ /* private fields */ }
Expand description

Reads the contents of a SharedAlignedBuffer front to back, see SharedAlignedBuffer::reader().

Bytes are borrowed from the buffer for as long as the buffer is borrowed, so any number of them can be held at once, while Self::read_buffer() creates buffers that reference a part of the contents without copying them.

A read that fails leaves the reader unchanged.

Implementations§

Source§

impl<'a, A> SharedAlignedBufferReader<'a, A>
where A: Alignment,

Source

pub fn position(&self) -> u32

Number of bytes read so far, including padding

Source

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

Bytes that were not read yet

Source

pub fn read_to_alignment<B>(&mut self) -> Result<&'a [u8], ReadError>
where B: Alignment,

Read padding up to the next multiple of B bytes from the beginning of the contents.

Returns padding bytes, which are empty if the position is already a multiple of B, so that formats that require zero padding can check them.

Source

pub fn read_bytes(&mut self, len: u32) -> Result<&'a [u8], ReadError>

Read the next len bytes

Source

pub fn read_bytes_array<const N: usize>( &mut self, ) -> Result<&'a [u8; N], ReadError>

Read the next N bytes

Source

pub fn read_buffer<B>( &mut self, len: u32, ) -> Result<SharedAlignedBuffer<B>, ReadError>
where B: Alignment,

Create a buffer that references the next len bytes without copying them.

The bytes must be aligned to B in memory, Self::read_to_alignment() reads padding in front of them if necessary. The new buffer keeps the whole allocation alive unless it is empty, see SharedAlignedBuffer::into_standalone().

Source

pub fn read_trivial<T>(&mut self) -> Result<&'a T, ReadError>
where T: AnyBitPattern,

Read a value of a trivial type.

The bytes must be aligned for T in memory, Self::read_to_alignment() reads padding in front of them if necessary. Unaligned reads values that are not aligned.

Source

pub fn read_trivial_array<T, const N: usize>( &mut self, ) -> Result<&'a [T; N], ReadError>
where [T; N]: AnyBitPattern,

Read N values of a trivial type, like Self::read_trivial()

Source

pub fn read_trivial_slice<T>( &mut self, count: u32, ) -> Result<&'a [T], ReadError>
where T: AnyBitPattern,

Read count values of a trivial type, like Self::read_trivial()

Trait Implementations§

Source§

impl<'a, A> Clone for SharedAlignedBufferReader<'a, A>
where A: Alignment + Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, A> Debug for SharedAlignedBufferReader<'a, A>
where A: Alignment + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, A> Forget for SharedAlignedBufferReader<'a, A>

§

impl<'a, A> Freeze for SharedAlignedBufferReader<'a, A>

§

impl<'a, A> Move for SharedAlignedBufferReader<'a, A>

§

impl<'a, A> RefUnwindSafe for SharedAlignedBufferReader<'a, A>
where A: RefUnwindSafe,

§

impl<'a, A> Send for SharedAlignedBufferReader<'a, A>
where &'a SharedAlignedBuffer<A>: Send,

§

impl<'a, A> Sync for SharedAlignedBufferReader<'a, A>
where InnerBuffer: Sync,

§

impl<'a, A> Unpin for SharedAlignedBufferReader<'a, A>
where &'a SharedAlignedBuffer<A>: Unpin,

§

impl<'a, A> UnsafeUnpin for SharedAlignedBufferReader<'a, A>

§

impl<'a, A> UnwindSafe for SharedAlignedBufferReader<'a, 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 = !

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.