Skip to main content

ArrayElement

Trait ArrayElement 

Source
pub trait ArrayElement: Sealed + Copy {
    const SCALAR: ScalarType;

    // Required methods
    fn to_bytes(self) -> Vec<u8> ⓘ;
    fn from_element(element: &Element) -> Option<Self>;
}
Expand description

A scalar type an array can be written from and read back as.

Implemented for the numeric types ASDF’s core/ndarray schema names, so AsdfBuilder::set_array and AsdfFile::read_array_of work for any of them without a method per type.

Sealed: the set of scalar types is the schema’s, not the caller’s.

Required Associated Constants§

Source

const SCALAR: ScalarType

The schema’s name for this type.

Required Methods§

Source

fn to_bytes(self) -> Vec<u8> ⓘ

This value’s bytes in the machine’s own order.

Source

fn from_element(element: &Element) -> Option<Self>

Read a decoded element as this type, or None if it is not one.

Narrowing that would lose the value is a None rather than a silent truncation: a caller asking for Vec<i32> wants the numbers, not whatever survives the cast.

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 ArrayElement for f32

Source§

const SCALAR: ScalarType = ScalarType::Float32

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for f64

Source§

const SCALAR: ScalarType = ScalarType::Float64

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for i8

Source§

const SCALAR: ScalarType = ScalarType::Int8

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for i16

Source§

const SCALAR: ScalarType = ScalarType::Int16

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for i32

Source§

const SCALAR: ScalarType = ScalarType::Int32

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for i64

Source§

const SCALAR: ScalarType = ScalarType::Int64

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for u8

Source§

const SCALAR: ScalarType = ScalarType::Uint8

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for u16

Source§

const SCALAR: ScalarType = ScalarType::Uint16

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for u32

Source§

const SCALAR: ScalarType = ScalarType::Uint32

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Source§

impl ArrayElement for u64

Source§

const SCALAR: ScalarType = ScalarType::Uint64

Source§

fn to_bytes(self) -> Vec<u8> ⓘ

Source§

fn from_element(element: &Element) -> Option<Self>

Implementors§