kornelski / imgref

A trivial Rust struct for interchange of pixel buffers with width, height & stride
https://lib.rs/crates/imgref
Apache License 2.0
59 stars 6 forks source link

Why does index/index_mut require Pixel to implement Copy #12

Closed mdcrapse closed 4 years ago

mdcrapse commented 4 years ago

The following code does not compile because String does not implement Copy:

fn main() {
    let vec = imgref::ImgVec::new(vec!["world!`".to_string()], 1, 1);
    println!("Hello, {}", vec[(0usize, 0usize)]);
}

If you look at imgref/ops.rs it requires Pixel to implement Copy. Why is Copy required?

kornelski commented 4 years ago

This library is written with images in mind, and I haven't seen an actual pixel definition that isn't copyable. I hope this catches mistakes.

mdcrapse commented 4 years ago

My bad, I was treating ImgVec like a 2d vector. Thanks for the clarification.