pub trait PrimitiveColorChannel: PrimitiveNum {
const MAX_INTENSITY: Self;
// Provided method
fn color_cast_from<SrcT: PrimitiveColorChannel>(src: SrcT) -> Self { ... }
}
Expand description
Types that can be used as a color channel.
Implemented for u8
, u16
, u32
, f32
and f64
. For integer types, the
whole range is used (0 to T::max_value()
) while for floats, the values
are always between 0 and 1.
Required Associated Constants§
Sourceconst MAX_INTENSITY: Self
const MAX_INTENSITY: Self
The value representing maximum intensity.
T::max_value()
for integer, 1.0
for floats. The minimum intensity
is always 0.
Provided Methods§
Sourcefn color_cast_from<SrcT: PrimitiveColorChannel>(src: SrcT) -> Self
fn color_cast_from<SrcT: PrimitiveColorChannel>(src: SrcT) -> Self
Creates one channel type from another one, converting correctly between values.
This is not a simple as
cast or even cast::lossy
. For example,
255u8
becomes 1.0f32
or u16::max_value()
. These casts are not
lossless, but might round the value a bit (like casting rigor
AllowRounding
).
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.