Skip to main content

Field

Trait Field 

Source
pub trait Field: Sized {
    const SIZE: Option<usize>;

    // Required methods
    fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>;
    fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>;
}
Expand description

Trait for reading/writing protocol fields from raw buffers.

Required Associated Constants§

Source

const SIZE: Option<usize>

The size of this field in bytes (None for variable-length fields).

Required Methods§

Source

fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>

Read the field value from the buffer at the given offset.

Source

fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>

Write the field value to the buffer at the given offset.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Field for u8

Source§

const SIZE: Option<usize>

Source§

fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>

Source§

fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>

Source§

impl Field for u16

Source§

const SIZE: Option<usize>

Source§

fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>

Source§

fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>

Source§

impl Field for u32

Source§

const SIZE: Option<usize>

Source§

fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>

Source§

fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>

Source§

impl Field for u64

Source§

const SIZE: Option<usize>

Source§

fn read(buf: &[u8], offset: usize) -> Result<Self, FieldError>

Source§

fn write(&self, buf: &mut [u8], offset: usize) -> Result<(), FieldError>

Implementors§