pub struct DataView(_);
Expand description

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

Returns the number of bytes in the instance.

Copies a (potentially unaligned) value from the view.

Copies a (potentially unaligned) value from the view.

Copies a (potentially unaligned) value from the view.

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

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

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

Reads an aligned value from the view.

Reads an aligned value from the view.

Reads an aligned value from the view.

Reads an aligned value from the view.

Reads an aligned value from the view.

Reads an aligned value from the view.

Reads an aligned slice from the view.

Reads an aligned slice from the view.

Reads an aligned slice from the view.

Reads an aligned slice from the view.

Reads an aligned slice from the view.

Reads an aligned slice from the view.

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

Writes a value to the view.

Writes a value to the view.

Writes a value to the view.

Index the DataView creating a subview.

Index the DataView creating a mutable subview.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Returns the object’s memory as a byte slice.
Returns the object’s memory as a mutable byte slice.
Returns a data view into the object’s memory.
Returns a mutable data view into the object’s memory.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more