You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)]structFlirRawData{#[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>,}fnraw_thermal_parser<R:Read + Seek>(reader:&mutR,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?
The text was updated successfully, but these errors were encountered:
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
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
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
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:
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 theR
type in the function definition, then it complains aboutSeek
not being implemented forR
. If I remove both, then it compiles, but then R can't be used for parsing in any way that I can see.What's going wrong here?
The text was updated successfully, but these errors were encountered: