Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom parser documentation doesn't specify Read + Seek bounds come from binread::io not std::io #23

Closed
anieuwland opened this issue Oct 8, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@anieuwland
Copy link

I'm trying to define a custom parser, but I'm getting typing errors that make it impossible to do any parsing. Basically, it looks like this:

use std::io::Read;
use std::io::Seek;
use byteorder::{BigEndian, ReadBytesExt};
use binread::*;
// (others left out for brevity, removing imports doesn't solve issue however)

#[derive(Debug)]
#[derive(BinRead)]
struct FlirRawData {
    #[br(pad_before = 2)]
    #[br(little)]
    image_width: u16,
    #[br(little)]
    image_height: u16,
    image_type: u16,
    #[br(pad_before = 26)]
    #[br(parse_with = raw_image_parser)]
    raw_image Vec<u8>,
}

fn raw_thermal_parser<R: Read + Seek>(reader: &mut R, ro: &ReadOptions, _: ()) -> BinResult<Vec<u8>> {
    Ok(Vec::new())
}

Basically, it's like straight from the documentation. Unfortunately this fails to compile with the error that the trait bounds aren't satisfied (as below). If I remove the Read trait from the R type in the function definition, then it complains about Seek not being implemented for R. If I remove both, then it compiles, but then R can't be used for parsing in any way that I can see.

error[E0277]: the trait bound `R: std::io::Read` is not satisfied
   --> src/thermograms/flir.rs:174:23
    |
174 |     #[br(parse_with = raw_image_parser)]
    |                       ^^^^^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `R`

What's going wrong here?

@jam1garner
Copy link
Owner

Ah ok! I should definitely clarify that in the docs. But Read + Seek there refers to binread::io::{Read, Seek};, which are what allows binread to work in no_std.

If you change your imports to use those, it will work. The interface should be the same, and binread::io::Read is implemented for std::io::Read, but unfortunately since all of std::io is std-only this is a bit of a hack that's kinda required.

Keeping this issue open as a documentation issue though until I (or someone else) gets around to fixing it.

@jam1garner jam1garner added the documentation Improvements or additions to documentation label Oct 8, 2020
@jam1garner jam1garner changed the title parse_with doesn't satisfy Read + Seek bounds Custom parsers don't specify Read + Seek bounds come from binread::io not std::io Oct 8, 2020
@jam1garner jam1garner changed the title Custom parsers don't specify Read + Seek bounds come from binread::io not std::io Custom parser documentation doesn't specify Read + Seek bounds come from binread::io not std::io Oct 8, 2020
@jam1garner
Copy link
Owner

Marking this as closed due to #38 making this probably not needed. Reopen if it's a problem for you still.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants