I'm using the image crate for picture manipulation and want to create a little wrapper to make my code a bit fancier.
extern crate image;
const BLACK: [u8; 4] = [0, 0, 0, 255];
const WHITE: [u8; 4] = [255, 255, 255, 255];
const RED: [u8; 4] = [255, 0, 0, 255];
pub struct Picture {
buffer: image::ImageBuffer,
width: u32,
height: u32
}
impl Picture {
// My functions like fill(), line() etc.
}
But when I compile this, I have an error:
src\pic.rs:11:13: 11:31 error: wrong number of type arguments: expected 2, found 0 [E0243]
src\pic.rs:11 buffer: image::ImageBuffer,
^~~~~~~~~~~~~~~~~~
In the source, I saw that ImageBuffer
accepts two arguments:
pub struct ImageBuffer<P: Pixel, Container> {
width: u32,
height: u32,
_phantom: PhantomData<P>,
data: Container,
}
So I decided to put those arguments in the Picture
declaration:
pub struct Picture {
buffer: image::ImageBuffer<image::Pixel>,
}
And got another error:
src\pic.rs:11:32: 11:44 error: the value of the associated type `Subpixel` (from the trait `pic::image::buffer::Pixel`) must be specified [E0191]
src\pic.rs:11 buffer: image::ImageBuffer<image::Pixel>,
^~~~~~~~~~~~
That means I must specify some value for the Subpixel
type, and I don't get it. I don't know how to declare that Container
type, I can't find anything useful in the sources. I tried to re-read the Rust Book, examples, rustc --explain E0191
but I am still lost.
update:
In sources found next declaration:
impl<P, Container> ImageBuffer<P, Container>
where P: Pixel + 'static,
P::Subpixel: 'static,
Container: Deref<Target=[P::Subpixel]>
And Subpixel
is:
/// Primitive trait from old stdlib
pub trait Primitive: Copy + NumCast + Num + PartialOrd<Self> + Clone + Bounded {
}
But it not public for my crate.