On 04/07/2012 08:58 PM, Mic wrote:
Hi,
I am getting the following errors:

$ rustc csv_create.rs <http://csv_create.rs>
csv_create.rs:17:1: 17:14 error: attempted access of field write_str on type core::io::writer, but no public field or method with that name was found csv_create.rs:17 <http://csv_create.rs:17> rdr.write_str("aaa, bbb,ccc , ddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn\n");
                                  ^~~~~~~~~~~~~
csv_create.rs:17:1: 17:78 error: mismatched types: expected function or native function but found _|_ csv_create.rs:17 <http://csv_create.rs:17> rdr.write_str("aaa, bbb,ccc , ddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn\n"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

with the following code:

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

fn main(args: [str]) {

let r = io::file_writer("csv.csv" , [io::create, io::truncate]); // r is result<reader, err_str>
    if result::is_failure(r) {
        fail result::get_err(r);
    }

    let rdr = result::get(r);

    let count = 0;
    while true {

        if count == 4000000 { break; }
rdr.write_str("aaa, bbb,ccc , ddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn\n");
        count += 1;
    }
}

What did I do wrong and would it possible to rewrite the while loop with for loop?


I believe the problem is that you are using a writer type but have imported a reader impl. if you add an `import io::writer_util;` statement then it will get farther.

The most concise way to write your while loop would be using `iter::repeat` which just executes a function a specific number of times, like `iter::repeat(4000000) {|| ... }`. Sadly `iter::repeat` can't be used in a for loop yet. Our iteration strategy still needs an overhaul to be compatible with `for`.

-Brian

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

Reply via email to