Closed xtofs closed 3 years ago
Could you please provide a minimal example?
use abnf::rulelist;
use std::error::Error;
fn main() -> std::result::Result<(), Box<dyn Error>> {
let input = std::fs::read_to_string("foo.abnf")?;
println!("{:#?}", input);
let rules = rulelist("a = b / c\nc = *(d e)\n") ?;
println!("{:#?}", rules);
Ok(())
}
$ cargo build
Compiling abnf-repro v0.1.0 (~/abnf-repro)
error[E0277]: the trait bound `abnf::error::ParseError: std::error::Error` is not satisfied
--> src/main.rs:8:35
|
8 | let rules = rulelist(&input) ?;
| ^ the trait `std::error::Error` is not implemented for `abnf::error::ParseError`
|
= note: required because of the requirements on the impl of `From<abnf::error::ParseError>` for `Box<dyn std::error::Error>`
= note: required by `from`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `abnf-repro`
To learn more, run the command again with --verbose.
version used:
[dependencies]
abnf = "0.10.0"
Ah, I see. By using the ?-operator, you basically tell Rust to convert ParseError
into Box<dyn Error>
. This is only possible when ParseError
implements Error
. However,
the trait `std::error::Error` is not implemented for `abnf::error::ParseError
tells you that this is not the case. Would you like to implement std::error::Error
for ParseError
in src/error.rs
and open a Pull Request? This should be easy to do, because you don't need to implement any trait-method. If you are not in a position to do it, I can do it myself tomorrow.
ParseError
now implements Error
(see 6fa4978fb9a4b81e8ea1d984983fbf0728d1c539).
For the rulelist function to work together with the ? operator the abnf::error::ParseError struct needs to implement some traits.
At the moment using it with lead to an error:
Not sure how to do it myself but some comments can be found here see https://stackoverflow.com/questions/59568278/why-does-the-operator-report-the-error-the-trait-bound-noneerror-error-is-no and/or https://doc.rust-lang.org/src/std/io/error.rs.html#549