Hi,

I'm learning how to open a file and write simple text data in it. I managed
something to work but was wondering whether I had to cast my filestream as
a writer:


    use std::path::Path;
    use std::rt::io::Writer;
    use std::rt::io::file::open;
    use std::rt::io::{Create, ReadWrite};

    let p = &Path("test.txt");
    let mut stream = match open(p, Create, ReadWrite) {
        Some(s) => s,
        None => fail!("whoops! I'm sure this raised, anyways..")
    };

    writeln!(&mut stream as &mut Writer, "test {}, {}, {aa}", 1, 3.0, aa=2);


Is that the simplest way to open a file and write in it? I find the "&mut
stream as &mut Writer" a bit surprising.

cheers,

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

Reply via email to