Struct dataview::DataView

source ·
#[repr(transparent)]
pub struct DataView { /* private fields */ }
Expand description

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

Operations

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

  • read(offset)

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

  • read_into(offset, dest)

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

  • get(offset)

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

  • get_mut(offset)

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

  • slice(offset, len)

    Gets 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)

    Gets 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 returns None then the Unchecked variation invokes Undefined Behavior.

Implementations

Returns a data view into the object’s memory.

Returns a mutable data view into the object’s memory.

Returns the number of bytes in the instance.

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

Reads a (potentially unaligned) value from the view.

Reads a (potentially unaligned) value from the view.

Reads a (potentially unaligned) value from the view.

Reads a (potentially unaligned) value from the view.

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

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

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

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

Gets an aligned reference into the view.

Gets an aligned reference into the view.

Gets an aligned reference into the view.

Gets an aligned reference into the view.

Gets an aligned mutable reference into the view.

Gets an aligned mutable reference into the view.

Gets an aligned mutable reference into the view.

Gets an aligned mutable reference into the view.

Gets an aligned slice into the view.

Gets an aligned slice into the view.

Gets an aligned slice into the view.

Gets an aligned slice into the view.

Gets an aligned mutable slice into the view.

Gets an aligned mutable slice into the view.

Gets an aligned mutable slice into the view.

Gets an aligned mutable slice into the view.

Writes a value into the view.

Writes a value into the view.

Writes a value into the view.

Writes a value into 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

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
Returns a zero-initialized instance of the type.
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.