Struct View

Source
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>

Source

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

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.

Source

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

Source

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

Source

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

Source

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

Source

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>

Source

pub fn packet_type(&self) -> <packet_type as StorageToFieldView<&[u8]>>::View

Return a FieldView with read access to the packet_type field

Source

pub fn code(&self) -> <code as StorageToFieldView<&[u8]>>::View

Return a FieldView with read access to the code field

Source

pub fn checksum(&self) -> <checksum as StorageToFieldView<&[u8]>>::View

Return a FieldView with read access to the checksum field

Source

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

Source

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>

Source

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

Source

pub fn code_mut(&mut self) -> <code as StorageToFieldView<&mut [u8]>>::View

Return a FieldView with write access to the code field

Source

pub fn checksum_mut( &mut self, ) -> <checksum as StorageToFieldView<&mut [u8]>>::View

Return a FieldView with write access to the checksum field

Source

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

Source

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> Freeze for View<S>
where S: Freeze,

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.