Trait PixelBound

Source
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§

Source

fn min_pixel() -> Self

The minimum value a pixel can take

Source

fn max_pixel() -> Self

The maximum value a pixel can take

Provided Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl PixelBound for f32

Source§

impl PixelBound for f64

Source§

impl PixelBound for i8

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for i16

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for i32

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for i64

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for i128

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for u8

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for u16

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for u32

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for u64

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Source§

impl PixelBound for u128

Source§

fn min_pixel() -> Self

Source§

fn max_pixel() -> Self

Implementors§