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]
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]
impl DataView
[src]pub fn try_copy_into<T: Pod + ?Sized>(
&self,
offset: usize,
dest: &mut T
) -> Option<()>
[src]
&self,
offset: usize,
dest: &mut T
) -> Option<()>
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]
&self,
offset: usize,
dest: &mut T
)
Copies a (potentially unaligned) value from the view into the destination.
impl DataView
[src]
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]
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]
impl DataView
[src]pub fn try_slice_mut<T: Pod>(
&mut self,
offset: usize,
len: usize
) -> Option<&mut [T]>
[src]
&mut self,
offset: usize,
len: usize
) -> Option<&mut [T]>
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]
&mut self,
offset: usize,
len: usize
) -> &mut [T]
Reads an aligned slice from the view.
impl DataView
[src]
impl DataView
[src]pub fn try_write<T: Pod + ?Sized>(
&mut self,
offset: usize,
value: &T
) -> Option<()>
[src]
&mut self,
offset: usize,
value: &T
) -> Option<()>
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]
&mut self,
offset: usize,
value: &T
)
Writes a value to the view.
impl DataView
[src]
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]
&mut self,
range: R
) -> Option<&mut DataView>
Index the DataView creating a mutable subview.
Trait Implementations
impl<R: RangeBounds<usize>> Index<R> for DataView
[src]
impl<R: RangeBounds<usize>> Index<R> for DataView
[src]impl<R: RangeBounds<usize>> IndexMut<R> for DataView
[src]
impl<R: RangeBounds<usize>> IndexMut<R> for DataView
[src]impl Pod for DataView
[src]
impl Pod for DataView
[src]fn zeroed() -> Self where
Self: Sized,
[src]
Self: Sized,
fn as_bytes(&self) -> &[u8]
[src]
fn as_bytes_mut(&mut self) -> &mut [u8]
[src]
fn as_data_view(&self) -> &DataView
[src]
fn as_data_view_mut(&mut self) -> &mut DataView
[src]
fn transmute<T: Pod>(self) -> T where
Self: Sized,
[src]
Self: Sized,
fn transmute_ref<T: Pod>(&self) -> &T where
Self: Sized,
[src]
Self: Sized,
fn transmute_mut<T: Pod>(&mut self) -> &mut T where
Self: Sized,
[src]
Self: Sized,