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:

define_layout!(icmp_packet, BigEndian, {
    packet_type: u8,
    code: u8,
    checksum: u16,
    rest_of_header: [u8; 4],
    data_section: [u8],
});

Implementations

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

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.

Destroy the View and return a field accessor to the packet_type field owning the storage. This is mostly useful for FieldView::extract

Destroy the View and return a field accessor to the code field owning the storage. This is mostly useful for FieldView::extract

Destroy the View and return a field accessor to the checksum field owning the storage. This is mostly useful for FieldView::extract

Destroy the View and return a field accessor to the rest_of_header field owning the storage. This is mostly useful for FieldView::extract

Destroy the View and return a field accessor to the data_section field owning the storage. This is mostly useful for FieldView::extract

Return a FieldView with read access to the packet_type field

Return a FieldView with read access to the code field

Return a FieldView with read access to the checksum field

Return a FieldView with read access to the rest_of_header field

Return a FieldView with read access to the data_section field

Return a FieldView with write access to the packet_type field

Return a FieldView with write access to the code field

Return a FieldView with write access to the checksum field

Return a FieldView with write access to the rest_of_header field

Return a FieldView with write access to the data_section field

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 the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.