I'm trying to work through Rust and using serde_yml as opposed to serde_yaml which has caused me much great confusion, and can't seem to find examples for parsing yaml from a file. I've been running into this error ...
error[E0277]: the trait bound `Result<File, std::io::Error>: std::io::Read` is not satisfied
--> src/main.rs:77:39
|
77 | let yaml = serde_yml::from_reader(f)?;
| ---------------------- ^ the trait `std::io::Read` is not implemented for `Result<File, std::io::Error>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `from_reader`
--> /home/pepp/.cargo/registry/src/index.crates.io-1949cf2c6b52557f/serde_yml-0.0.12/src/de.rs:2326:8
|
2324 | pub fn from_reader<R, T>(rdr: R) -> Result<T>
| ----------- required by a bound in this function
2325 | where
2326 | R: io::Read,
| ^^^^^^^^ required by this bound in `from_reader`
For more information about this error, try `rustc --explain E0277`.
My function is ...
fn parse_yml(conf: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
println!("conf: {:?}", conf);
let f = File::open(conf);
let yaml = serde_yml::from_reader(f)?;
println!("yaml: {}", yaml);
Ok(())
}
My understanding is that File already contains the read trait, so when I read E0277, I'm confused about implementing a trait on something it already has. E0277 seems to be about implementing a user defined trait.
?is unimaginatively called "the?operator". Take a look at chapter 9.2 of the book, in particular the section on?.