pub trait PixelBound {
// Required methods
fn min_pixel() -> Self;
fn max_pixel() -> Self;
// Provided method
fn is_integral() -> bool { ... }
}
Expand description
When working with pixel data types may have odd bitdepths or not use the
full range of the value. We can’t assume every image with u8
ranges from
[0..255]. Additionally, floating point representations of pixels normally
range from [0.0..1.0]. PixelBound
is an attempt to solve this issue.
Unfortunately, type aliases don’t really create new types so if you wanted to create a pixel with a reduced bound you’d have to create something like:
struct LimitedU8(u8);
impl PixelBound for LimitedU8 {
fn min_pixel() -> Self {
LimitedU8(16u8)
}
fn max_pixel() -> Self {
LimitedU8(160u8)
}
}
And then implement the required numerical traits just calling the
corresponding methods in `u8`
Required Methods§
Provided Methods§
Sourcefn is_integral() -> bool
fn is_integral() -> bool
If this is a non-floating point value return true
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.