Closed

Description
I want to return an object containing a specific type
I tried this code:
fn get_file_parser() {
let file = File::open("/Users/me/dev/rust/foobar/examples/books.xml").unwrap();
let file = BufReader::new(file);
EventReader::new(file)
}
I expected to see this happen:
This could be a better suggestion
fn get_file_parser() -> xml::EventReader<std::io::BufReader<std::fs::File>> {
Instead, this happened:
error[E0308]: mismatched types
--> src/lib.rs:23:5
|
23 | EventReader::new(file)
| ^^^^^^^^^^^^^^^^^^^^^^ expected (), found struct `xml::EventReader`
|
= note: expected type `()`
found type `xml::EventReader<std::io::BufReader<std::fs::File>>`
help: try adding a semicolon
|
23 | EventReader::new(file);
| ^
help: try adding a return type
|
20 | fn get_file_parser<T: std::io::Read>() -> xml::EventReader<_> {
| ^^^^^^^^^^^^^^^^^^^^^^
Meta
rustc --version --verbose
:
Backtrace:
rustc 1.21.0 (3b72af9 2017-10-09)
binary: rustc
commit-hash: 3b72af9
commit-date: 2017-10-09
host: x86_64-apple-darwin
release: 1.21.0
LLVM version: 4.0