Skip to main content

Element

Trait Element 

Source
pub unsafe trait Element:
    Send
    + Sync
    + 'static {
    type Ref<'a>: Copy + Debug;
    type Spans: Spans;

    const INLINE_FIXED: bool;

    // Required methods
    fn validate(bytes: &[u8]) -> bool;
    unsafe fn read<'a>(ptr: *const u8, len: usize) -> Self::Ref<'a>
       where Self: 'a;

    // Provided method
    fn fmt_row<'a, I>(values: I, f: &mut Formatter<'_>) -> Result
       where I: Iterator<Item = Self::Ref<'a>>,
             Self: 'a { ... }
}
Expand description

A type of the values a Buf holds: where they are in its storage, see Spans, and what octets are one of them.

This is implemented for every PackedElement, and for str, whose values are at the spans of a table.

§Safety

Self::read must be sound for any octets Self::validate accepts.

Required Associated Constants§

Source

const INLINE_FIXED: bool

Whether a scalar of this type is held in place of a storage, which only a packed type small enough can be.

Required Associated Types§

Source

type Ref<'a>: Copy + Debug

How one value is given out: by value for a packed type, borrowed for a string.

Source

type Spans: Spans

Where the values are in the storage.

Required Methods§

Source

fn validate(bytes: &[u8]) -> bool

Whether these octets are one valid value.

Source

unsafe fn read<'a>(ptr: *const u8, len: usize) -> Self::Ref<'a>
where Self: 'a,

The value in these octets.

§Safety

The octets must have been accepted by Self::validate, and be aligned for a packed type.

Provided Methods§

Source

fn fmt_row<'a, I>(values: I, f: &mut Formatter<'_>) -> Result
where I: Iterator<Item = Self::Ref<'a>>, Self: 'a,

Format the values of one row of a buffer for Debug, along its first dimension, within the brackets of that row: separated by commas unless a type has a better way.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Element for bool

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = bool

Source§

type Spans = PackedSpans<bool>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> bool
where bool: 'a,

Source§

impl Element for f32

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = f32

Source§

type Spans = PackedSpans<f32>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> f32
where f32: 'a,

Source§

impl Element for f64

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = f64

Source§

type Spans = PackedSpans<f64>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> f64
where f64: 'a,

Source§

impl Element for i8

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = i8

Source§

type Spans = PackedSpans<i8>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> i8
where i8: 'a,

Source§

impl Element for i16

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = i16

Source§

type Spans = PackedSpans<i16>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> i16
where i16: 'a,

Source§

impl Element for i32

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = i32

Source§

type Spans = PackedSpans<i32>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> i32
where i32: 'a,

Source§

impl Element for i64

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = i64

Source§

type Spans = PackedSpans<i64>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> i64
where i64: 'a,

Source§

impl Element for str

Source§

const INLINE_FIXED: bool = false

Source§

type Ref<'a> = &'a str

Source§

type Spans = TableSpans

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, len: usize) -> &'a str
where str: 'a,

Source§

impl Element for u8

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = u8

Source§

type Spans = PackedSpans<u8>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> u8
where u8: 'a,

Source§

fn fmt_row<'a, I>(values: I, f: &mut Formatter<'_>) -> Result
where I: Iterator<Item = u8>, u8: 'a,

Source§

impl Element for u16

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = u16

Source§

type Spans = PackedSpans<u16>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> u16
where u16: 'a,

Source§

impl Element for u32

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = u32

Source§

type Spans = PackedSpans<u32>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> u32
where u32: 'a,

Source§

impl Element for u64

Source§

const INLINE_FIXED: bool

Source§

type Ref<'a> = u64

Source§

type Spans = PackedSpans<u64>

Source§

fn validate(bytes: &[u8]) -> bool

Source§

unsafe fn read<'a>(ptr: *const u8, _len: usize) -> u64
where u64: 'a,

Implementors§