pub struct View<S: AsRef<[u8]>> { /* private fields */ }
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:
binary_layout!(icmp_packet, BigEndian, {
packet_type: u8,
code: u8,
checksum: u16,
rest_of_header: [u8; 4],
data_section: [u8],
});
Implementations§
Source§impl<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
Source§impl<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
Source§impl<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