jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
545 stars 35 forks source link

`?` operator has incompatible types with try_map and parse_with #239

Closed Emilgardis closed 7 months ago

Emilgardis commented 7 months ago

this works in 0.11

#[derive(BinRead,)]
#[br(little)]
pub struct Meta {
    /// ID
    pub id: [u8; 6],
    /// Serial number
    #[br(pad_before = 1, parse_with = binrw::helpers::until_eof, try_map = String::from_utf8)]
    pub serial_number: String,
}

it seems to no longer work in 0.13, giving me

error[E0308]: `?` operator has incompatible types
  --> src/lib.rs:11:10
   |
11 | #[derive(BinRead)]
   |          ^^^^^^^ expected `Vec<u8>`, found `String`
   |
   = note: `?` operator cannot convert from `std::string::String` to `Vec<u8>`
   = note: expected struct `Vec<u8>`
              found struct `std::string::String`
note: return type inferred to be `Vec<u8>` here
  --> src/lib.rs:11:10
   |
11 | #[derive(BinRead)]
   |          ^^^^^^^
   = note: this error originates in the derive macro `BinRead` (in Nightly builds, run with -Z macro-backtrace for more info)
help: call `Into::into` on this expression to convert `std::string::String` into `Vec<u8>`
   |
11 | #[derive(BinRead.into())]
   |                 +++++++

For more information about this error, try `rustc --explain E0308`.
csnover commented 7 months ago

Thanks for your report! This issue should be fixed in 0.13.2.