In c#/java i would have created an interface and instantiated an object that implments it. In the following code i dont know how to declare the variable based on the returned type.
This same thing would have happened if i would have used the from_path() function.
What is the correct declaration in this situation?
thanks again
dan@dan-VirtualBox:~/Downloads/csvreaders/rustcsvreader$ cargo build --release
Compiling rustcsvreader v0.1.0 (file:///home/dan/Downloads/csvreaders/rustcsvreader)
error[E0308]: mismatched types
--> src/main.rs:39:28
|
39 | csv::Reader::from_reader(d)
| ^ expected struct `std::io::Stdin`, found &[u8]
|
= note: expected type `std::io::Stdin`
found type `&[u8]`
let mut rdr : csv::Reader<_> =
if !mmap_open {
csv::Reader::from_reader(std::io::stdin())
} else {
let mmap = match Mmap::open_path("/home/dan/2008.csv", Protection::Read) {
Ok(mmap) => mmap,
Err(_) => { println!("mmap open fail"); return ; }
};
let d = unsafe { mmap.as_slice() };
csv::Reader::from_reader(d)
};
How did you know that was the trait? I didn't see that in the documentation.
thanks
also i get this now:
let mut rdr : csv::Reader<Box<std::io::Reader>> = ...
Compiling rustcsvreader v0.1.0 (file:///home/dan/Downloads/csvreaders/rustcsvreader)
error[E0412]: cannot find type `Reader` in module `std::io`
--> src/main.rs:30:41
|
30 | let mut rdr : csv::Reader<Box<std::io::Reader>> =
| ^^^^^^ did you mean `Read`?
|
= help: possible candidate is found in another module, you can import it into scope:
`use csv::Reader;`
csv::Reader - Rust - if you look right above that function doc you'll see a "impl<R: Read> Reader<R>" heading. That means all the functions doc'd below that heading (and until some other similar heading) are available when R:Read, and from_reader is fn from_reader(rdr: R) -> Reader<R>
io::Read and io::Write are very commonly used as type bounds for (sync) I/O. In Java land, that's roughly equivalent to InputStream and OutputStream.