Skip to main content

ChannelArray

Trait ChannelArray 

Source
pub trait ChannelArray<const N: usize>: Copy {
    // Required methods
    fn to_array(self) -> [f32; N];
    fn from_array(arr: [f32; N]) -> Self;
}
Expand description

Trait for types whose channels can be accessed as a fixed-size float array.

This is the foundation for channel arithmetic in the color system. Implementations exist for RGBA (4 channels) and RGB (3 channels).

The trait enables generic channel-wise operations:

use optic_color::*;

fn half_brightness<T: ChannelArray<N>, const N: usize>(c: T) -> T {
    channel_mul_scalar(c, 0.5)
}

See also: channel_lerp, channel_add, channel_mul.

Required Methods§

Source

fn to_array(self) -> [f32; N]

Convert to a float array of length N.

Source

fn from_array(arr: [f32; N]) -> Self

Construct from a float array of length N.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§