paolobarbolini / img-parts

Low level crate for reading and writing Jpeg, Png and RIFF image containers
https://crates.io/crates/img-parts
Apache License 2.0
25 stars 6 forks source link

image-rs example not working with newer versions of image #9

Open marcomastri opened 2 years ago

marcomastri commented 2 years ago

See https://github.com/image-rs/image/pull/1477

error[E0277]: the trait bound `Writer<BytesMut>: Seek` is not satisfied
   --> src/main.rs:70:22
    |
70  |         img.write_to(&mut out, out_format).expect("image encoded");
    |             -------- ^^^^^^^^ the trait `Seek` is not implemented for `Writer<BytesMut>`
    |             |
    |             required by a bound introduced by this call
    |
    = help: the following other types implement trait `Seek`:
              &File
              &mut S
              Box<S>
              BufReader<R>
              BufWriter<W>
              File
              std::io::Cursor<T>
              std::io::Empty
note: required by a bound in `DynamicImage::write_to`
   --> /Users/marco-bunker/.cargo/registry/src/github.com-1ecc6299db9ec823/image-0.24.4/./src/dynimage.rs:809:32
    |
809 |     pub fn write_to<W: Write + Seek, F: Into<ImageOutputFormat>>(
    |                                ^^^^ required by this bound in `DynamicImage::write_to`

For more information about this error, try `rustc --explain E0277`.
marcomastri commented 2 years ago

Wanting to stay close to the example, I made it work by replacing

let mut out = BytesMut::new().writer();
img.write_to(&mut out, out_format).expect("image encoded");
let out = out.into_inner().freeze();

with

let mut out = vec![];
img.write_to(&mut Cursor::new(&mut out), out_format).expect("image encoded");
let out = Bytes::from(out);

but I’m just dipping my toes in rust, and inexperienced with programming in general.