StructToArray

Trait StructToArray 

Source
pub trait StructToArray<Item, const N: usize>: Sized {
    const N_ATOMS: usize = N;

    // Required methods
    fn to_arr(self) -> [Item; N];
    fn from_arr(a: [Item; N]) -> Self;

    // Provided method
    fn num_fields() -> usize { ... }
}
Expand description

Convert between a homogeneous struct (all fields of type Item) and [Item; N].

This is intentionally value-based (consumes self / takes array by value). That keeps it safe and requires no layout assumptions.

Provided Associated Constants§

Source

const N_ATOMS: usize = N

Number of atomic items of type Item in the struct (recursively).

Required Methods§

Provided Methods§

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.

Implementors§