kornelski / rust-rgb

struct RGB for sharing pixels between crates
https://lib.rs/rgb
MIT License
98 stars 19 forks source link

add static bound to Pixel::Component to match HetPixel #134

Closed ripytide closed 2 weeks ago

kornelski commented 2 weeks ago

I'm afraid it could have a fallout for generic code.

There's static on the outer type that prevents accidental references. But this could infect function return types, other containers.

ripytide commented 2 weeks ago

I ran into this error briefly with the following bit of code:

type Component<I> = <<I as GenericImageView>::Pixel as Pixel>::Component;

/// Convert the supplied image to grayscale. Alpha channel is discarded.
pub fn grayscale<I: GenericImageView>(
    image: &I,
) -> ImageBuffer<Luma<Component<I>>, Vec<Component<I>>> {
    grayscale_with_type(image)
}
│rustc: the associated type `<<I as image::GenericImageView>::Pixel as rgb::ComponentMap>::Component` may not live long enough                                       │        
│the associated type `<<I as image::GenericImageView>::Pixel as rgb::ComponentMap>::Component` must be valid for the static lifetime..

I'm not that comfortable working with 'static bounds yet so I'll close this until I've done a bit more playing around and isolating of a smaller minimal working example.