Struct binary_layout::example::icmp_packet::View
source · [−]Expand description
The View struct defines the FieldView API. An instance of View wraps a storage (either borrowed or owned) and allows accessors for the layout fields.
This view is based on the following layout definition:
define_layout!(icmp_packet, BigEndian, {
packet_type: u8,
code: u8,
checksum: u16,
rest_of_header: [u8; 4],
data_section: [u8],
});Implementations
sourceimpl<S: AsRef<[u8]>> View<S>
impl<S: AsRef<[u8]>> View<S>
sourcepub fn new(storage: S) -> Self
pub fn new(storage: S) -> Self
You can create views over a storage by calling View::new.
S is the type of underlying storage. It can be
- Immutable borrowed storage:
&[u8] - Mutable borrowed storage:
&mut [u8] - Owning storage: impl
AsRef<u8>(for example:Vec<u8>)
sourcepub fn into_storage(self) -> S
pub fn into_storage(self) -> S
This destroys the view and returns the underlying storage back to you.
This is useful if you created an owning view (e.g. based on Vec<u8>)
and now need the underlying Vec<u8> back.
sourcepub fn into_packet_type(self) -> <packet_type as StorageIntoFieldView<S>>::View
pub fn into_packet_type(self) -> <packet_type as StorageIntoFieldView<S>>::View
Destroy the View and return a field accessor to the packet_type field owning the storage. This is mostly useful for FieldView::extract
sourcepub fn into_code(self) -> <code as StorageIntoFieldView<S>>::View
pub fn into_code(self) -> <code as StorageIntoFieldView<S>>::View
Destroy the View and return a field accessor to the code field owning the storage. This is mostly useful for FieldView::extract
sourcepub fn into_checksum(self) -> <checksum as StorageIntoFieldView<S>>::View
pub fn into_checksum(self) -> <checksum as StorageIntoFieldView<S>>::View
Destroy the View and return a field accessor to the checksum field owning the storage. This is mostly useful for FieldView::extract
sourcepub fn into_rest_of_header(
self
) -> <rest_of_header as StorageIntoFieldView<S>>::View
pub fn into_rest_of_header(
self
) -> <rest_of_header as StorageIntoFieldView<S>>::View
Destroy the View and return a field accessor to the rest_of_header field owning the storage. This is mostly useful for FieldView::extract
sourcepub fn into_data_section(
self
) -> <data_section as StorageIntoFieldView<S>>::View
pub fn into_data_section(
self
) -> <data_section as StorageIntoFieldView<S>>::View
Destroy the View and return a field accessor to the data_section field owning the storage. This is mostly useful for FieldView::extract
sourceimpl<S: AsRef<[u8]>> View<S>
impl<S: AsRef<[u8]>> View<S>
sourcepub fn packet_type(&self) -> <packet_type as StorageToFieldView<&[u8]>>::View
pub fn packet_type(&self) -> <packet_type as StorageToFieldView<&[u8]>>::View
Return a FieldView with read access to the packet_type field
sourcepub fn code(&self) -> <code as StorageToFieldView<&[u8]>>::View
pub fn code(&self) -> <code as StorageToFieldView<&[u8]>>::View
Return a FieldView with read access to the code field
sourcepub fn checksum(&self) -> <checksum as StorageToFieldView<&[u8]>>::View
pub fn checksum(&self) -> <checksum as StorageToFieldView<&[u8]>>::View
Return a FieldView with read access to the checksum field
sourcepub fn rest_of_header(
&self
) -> <rest_of_header as StorageToFieldView<&[u8]>>::View
pub fn rest_of_header(
&self
) -> <rest_of_header as StorageToFieldView<&[u8]>>::View
Return a FieldView with read access to the rest_of_header field
sourcepub fn data_section(&self) -> <data_section as StorageToFieldView<&[u8]>>::View
pub fn data_section(&self) -> <data_section as StorageToFieldView<&[u8]>>::View
Return a FieldView with read access to the data_section field
sourceimpl<S: AsRef<[u8]> + AsMut<[u8]>> View<S>
impl<S: AsRef<[u8]> + AsMut<[u8]>> View<S>
sourcepub fn packet_type_mut(
&mut self
) -> <packet_type as StorageToFieldView<&mut [u8]>>::View
pub fn packet_type_mut(
&mut self
) -> <packet_type as StorageToFieldView<&mut [u8]>>::View
Return a FieldView with write access to the packet_type field
sourcepub fn code_mut(&mut self) -> <code as StorageToFieldView<&mut [u8]>>::View
pub fn code_mut(&mut self) -> <code as StorageToFieldView<&mut [u8]>>::View
Return a FieldView with write access to the code field
sourcepub fn checksum_mut(
&mut self
) -> <checksum as StorageToFieldView<&mut [u8]>>::View
pub fn checksum_mut(
&mut self
) -> <checksum as StorageToFieldView<&mut [u8]>>::View
Return a FieldView with write access to the checksum field
sourcepub fn rest_of_header_mut(
&mut self
) -> <rest_of_header as StorageToFieldView<&mut [u8]>>::View
pub fn rest_of_header_mut(
&mut self
) -> <rest_of_header as StorageToFieldView<&mut [u8]>>::View
Return a FieldView with write access to the rest_of_header field
sourcepub fn data_section_mut(
&mut self
) -> <data_section as StorageToFieldView<&mut [u8]>>::View
pub fn data_section_mut(
&mut self
) -> <data_section as StorageToFieldView<&mut [u8]>>::View
Return a FieldView with write access to the data_section field
Auto Trait Implementations
impl<S> RefUnwindSafe for View<S> where
S: RefUnwindSafe,
impl<S> Send for View<S> where
S: Send,
impl<S> Sync for View<S> where
S: Sync,
impl<S> Unpin for View<S> where
S: Unpin,
impl<S> UnwindSafe for View<S> where
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more