Struct dataview::DataView[][src]

pub struct DataView(_);

Read and write data from and to the underlying byte buffer.

Construct the data view through Pod::as_data_view or Pod::as_data_view_mut.

Operations

Each set of operations may support a try, panicking and unchecked variations, see below for more information.

  • copy(offset)

    Copies a (potentially unaligned) value out of the view.

  • copy_into(offset, dest)

    Copies a (potentially unaligned) value out of the view into the dest argument.

  • read(offset)

    Returns a reference to the data given the offset. Errors if the final pointer is misaligned for the given type.

  • read_mut(offset)

    Returns a mutable reference to the data given the offset. Errors if the final pointer is misaligned for the given type.

  • slice(offset, len)

    Returns a slice to the data given the offset and len. Errors if the final pointer is misaligned for the given type.

  • slice_mut(offset, len)

    Returns a mutable slice to the data given the offset. Errors if the final pointer is misaligned for the given type.

  • write(offset, value)

    Writes a value to the view at the given offset.

Panics

Panicking methods have no prefix or suffix. They invoke the Try methods and panic if they return None.

When calling Panicking variation with an offset that ends up out of bounds or if the final pointer is misaligned for the given type the method panics with the message "invalid offset".

The relevant methods are annotated with #[track_caller] providing a useful location where the error happened.

Safety

The Unchecked methods have the _unchecked suffix and simply assume the offset is correct. This is Undefined Behavior when it results in an out of bounds read or write or if a misaligned reference is produced.

If the Try variation would have returned None then the Unchecked variation is Undefined Behavior.

Implementations

impl DataView[src]

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

Returns the number of bytes in the instance.

impl DataView[src]

pub fn try_copy<T: Pod>(&self, offset: usize) -> Option<T>[src]

Copies a (potentially unaligned) value from the view.

pub fn copy<T: Pod>(&self, offset: usize) -> T[src]

Copies a (potentially unaligned) value from the view.

pub unsafe fn copy_unchecked<T: Pod>(&self, offset: usize) -> T[src]

Copies a (potentially unaligned) value from the view.

impl DataView[src]

pub fn try_copy_into<T: Pod + ?Sized>(
    &self,
    offset: usize,
    dest: &mut T
) -> Option<()>
[src]

Copies a (potentially unaligned) value from the view into the destination.

pub fn copy_into<T: Pod + ?Sized>(&self, offset: usize, dest: &mut T)[src]

Copies a (potentially unaligned) value from the view into the destination.

pub unsafe fn copy_into_unchecked<T: Pod + ?Sized>(
    &self,
    offset: usize,
    dest: &mut T
)
[src]

Copies a (potentially unaligned) value from the view into the destination.

impl DataView[src]

pub fn try_read<T: Pod>(&self, offset: usize) -> Option<&T>[src]

Reads an aligned value from the view.

pub fn read<T: Pod>(&self, offset: usize) -> &T[src]

Reads an aligned value from the view.

pub unsafe fn read_unchecked<T: Pod>(&self, offset: usize) -> &T[src]

Reads an aligned value from the view.

impl DataView[src]

pub fn try_read_mut<T: Pod>(&mut self, offset: usize) -> Option<&mut T>[src]

Reads an aligned value from the view.

pub fn read_mut<T: Pod>(&mut self, offset: usize) -> &mut T[src]

Reads an aligned value from the view.

pub unsafe fn read_unchecked_mut<T: Pod>(&mut self, offset: usize) -> &mut T[src]

Reads an aligned value from the view.

impl DataView[src]

pub fn try_slice<T: Pod>(&self, offset: usize, len: usize) -> Option<&[T]>[src]

Reads an aligned slice from the view.

pub fn slice<T: Pod>(&self, offset: usize, len: usize) -> &[T][src]

Reads an aligned slice from the view.

pub unsafe fn slice_unchecked<T: Pod>(&self, offset: usize, len: usize) -> &[T][src]

Reads an aligned slice from the view.

impl DataView[src]

pub fn try_slice_mut<T: Pod>(
    &mut self,
    offset: usize,
    len: usize
) -> Option<&mut [T]>
[src]

Reads an aligned slice from the view.

pub fn slice_mut<T: Pod>(&mut self, offset: usize, len: usize) -> &mut [T][src]

Reads an aligned slice from the view.

pub unsafe fn slice_unchecked_mut<T: Pod>(
    &mut self,
    offset: usize,
    len: usize
) -> &mut [T]
[src]

Reads an aligned slice from the view.

impl DataView[src]

pub const fn tail_len<T>(&self, offset: usize) -> usize[src]

Returns the number of elements that would fit a slice starting at the given offset.

impl DataView[src]

pub fn try_write<T: Pod + ?Sized>(
    &mut self,
    offset: usize,
    value: &T
) -> Option<()>
[src]

Writes a value to the view.

pub fn write<T: Pod + ?Sized>(&mut self, offset: usize, value: &T)[src]

Writes a value to the view.

pub unsafe fn write_unchecked<T: Pod + ?Sized>(
    &mut self,
    offset: usize,
    value: &T
)
[src]

Writes a value to the view.

impl DataView[src]

pub fn index<R: RangeBounds<usize>>(&self, range: R) -> Option<&DataView>[src]

Index the DataView creating a subview.

pub fn index_mut<R: RangeBounds<usize>>(
    &mut self,
    range: R
) -> Option<&mut DataView>
[src]

Index the DataView creating a mutable subview.

Trait Implementations

impl AsMut<[u8]> for DataView[src]

impl AsRef<[u8]> for DataView[src]

impl<R: RangeBounds<usize>> Index<R> for DataView[src]

type Output = DataView

The returned type after indexing.

impl<R: RangeBounds<usize>> IndexMut<R> for DataView[src]

impl Pod for DataView[src]

Auto Trait Implementations

impl Send for DataView

impl !Sized for DataView

impl Sync for DataView

impl Unpin for DataView

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]