On 04/06/2012 06:48 PM, Mic wrote:
Hi
I have trouble to compile the following code:

import io::reader_util;
import vec::map;

fn main(args: [str]) {

    let r = io::file_reader(args[1]); // r is result<reader, err_str>
    if result::failure(r) {
        fail result::get_err(r);
    }

    let rdr = result::get(r);

    while !rdr.eof() {
        let line = rdr.read_line();
        io::println(line);
        if str::len(line) != 0u {
            let parts = vec::map(line.split_char(',')) {|s|
                str::trim(s)
            };
        }

    }
}

and got the errors:
$ rustc csv.rs <http://csv.rs>
csv.rs:17:33: 17:48 error: attempted access of field split_char on type str, but no public field or method with that name was found csv.rs:17 <http://csv.rs:17> let parts = vec::map(line.split_char(',')) {|s| ^~~~~~~~~~~~~~~ csv.rs:17:33: 17:53 error: the type of this value must be known in this context csv.rs:17 <http://csv.rs:17> let parts = vec::map(line.split_char(',')) {|s| ^~~~~~~~~~~~~~~~~~~~

What did I do wrong?


Hi Mic.

The available extension methods (as in `line.split_char(',')`) have been changing a lot recently, so my guess is that your compiler is just slightly out of date and doesn't have the `split_char` extension on `str`. Try updating to Rust HEAD where you will also notice that `result::failure` is now called `result::is_failure`.

-Brian

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to