These are chat archives for rust-lang/rust

24th
Sep 2016
Aleksandr Borovkov
@xander27
Sep 24 2016 12:19

Hi.
Im trying to use csv module in my first Rust program

use std::env;
use std::path::Path;
use std::error::Error;

extern crate csv;

fn foo(x: Iterator<Result<Vec<String>>>){
    for row in x {
        println!("{:?}", row);
    }
}

fn main() {
    let args: Vec<String> = env::args().collect();
    let args_number = args.len() - 1;

    let input_file_path = Path::new(&args[1]);
    print!("Input file path: `{:?}`", &input_file_path);

    let mut csv_reader = match csv::Reader::from_file(&input_file_path) {
        Err(why) => panic!("couldn't open {}: {}", &input_file_path.display(),
                                                   why.description()),
        Ok(reader) => reader,
    };
    foo(csv_reader.records());
}

csv_reader.records() has this type which implementing Iterator trait for type Item = Result<Vec<String>>. What signature should foo function have to accept csv_reader.records() as iterator? I dont want to bound it to specific types

Now I have compile error

   Compiling hello_world v0.1.0 (file:///C:/code/rust/hello_world)
src\main.rs:8:20: 8:39 error: wrong number of type arguments: expected 2, found 1 [E0243]
src\main.rs:8 fn foo(x: Iterator<Result<Vec<String>>>){
                                 ^~~~~~~~~~~~~~~~~~~
src\main.rs:8:20: 8:39 help: run `rustc --explain E0243` to see a detailed explanation
src\main.rs:8:11: 8:40 error: wrong number of type arguments: expected 0, found 1 [E0244]
src\main.rs:8 fn foo(x: Iterator<Result<Vec<String>>>){
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\main.rs:8:11: 8:40 help: run `rustc --explain E0244` to see a detailed explanation
src\main.rs:8:11: 8:40 error: the value of the associated type `Item` (from the trait `std::iter::Iterator`) must be specified [E0191]
src\main.rs:8 fn foo(x: Iterator<Result<Vec<String>>>){

Is it becouse I didnt specify lifetime argument?

Sergey Noskov
@Albibek
Sep 24 2016 12:23
Iterator trait has assotiated type, it is specified like this Iterator<Item=Type>
Result requires 2 types - the result type and the error type
Aleksandr Borovkov
@xander27
Sep 24 2016 12:26

Thanks a lot.

Iterator trait has assotiated type, it is specified like this `Iterator<Item=Type>.
This was the point. Somehow I missed any examples of this anywhere I googled