Skip to main content

Sample

Trait Sample 

Source
pub trait Sample:
    Sealed
    + Copy
    + PartialOrd
    + Default
    + Debug {
    const DATA_TYPE: DataType;
    const BYTES: usize;

    // Required methods
    fn to_f64(self) -> f64;
    fn from_f64(v: f64) -> Self;
    fn to_bits_u64(self) -> u64;
    fn from_bits_u64(v: u64) -> Self;
    fn is_integer() -> bool;
    fn into_lerc_data(v: Vec<Self>) -> SampleData;
    fn try_ref_lerc_data(data: &SampleData) -> Option<&[Self]>;
    fn try_from_lerc_data(data: SampleData) -> Result<Vec<Self>, SampleData>;
    fn from_le_slice(s: &[u8]) -> Self;
    fn extend_le_bytes(self, buf: &mut Vec<u8>);
    fn min_representable() -> f64;
}
Expand description

Trait for pixel types that can be encoded/decoded with LERC.

Implemented for i8, u8, i16, u16, i32, u32, f32, and f64.

Required Associated Constants§

Source

const DATA_TYPE: DataType

The corresponding LERC DataType discriminant.

Source

const BYTES: usize

Size of this type in bytes.

Required Methods§

Source

fn to_f64(self) -> f64

Convert this value to f64.

Source

fn from_f64(v: f64) -> Self

Create a value from an f64 (truncating/rounding as needed).

Source

fn to_bits_u64(self) -> u64

Reinterpret this value’s bits as a u64.

Source

fn from_bits_u64(v: u64) -> Self

Reinterpret a u64’s bits as this type.

Source

fn is_integer() -> bool

Returns true if this is an integer pixel type.

Source

fn into_lerc_data(v: Vec<Self>) -> SampleData

Wrap a Vec<Self> into the corresponding SampleData variant.

Source

fn try_ref_lerc_data(data: &SampleData) -> Option<&[Self]>

Try to borrow the pixel slice from a SampleData if the variant matches.

Source

fn try_from_lerc_data(data: SampleData) -> Result<Vec<Self>, SampleData>

Try to unwrap the pixel vector from a SampleData if the variant matches.

Source

fn from_le_slice(s: &[u8]) -> Self

Read a value from a little-endian byte slice. The slice must be at least BYTES long.

Source

fn extend_le_bytes(self, buf: &mut Vec<u8>)

Write this value as little-endian bytes to a Vec.

Source

fn min_representable() -> f64

The minimum representable value for this type as f64.

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

Source§

impl Sample for f64

Source§

impl Sample for i8

Source§

impl Sample for i16

Source§

impl Sample for i32

Source§

impl Sample for u8

Source§

impl Sample for u16

Source§

impl Sample for u32

Implementors§