On 23/06/13 12:53, Ashish Myles wrote:
I have been out of rust for a bit, and coming back to it, I am having
a difficult time adapting the front page example at
http://www.rust-lang.org/ to the trunk version of rust (updated last
night). I turned the example to

--------
use std::*;

fn main() {
     for ["Alice", "Bob", "Carol"].each |&name| {
         do task::spawn {
             let v = rand::rng().shuffle([1, 2, 3]);
             for v.each |&num| {
                 io::print(fmt!("%s says: '%d'\n", name, num))
             }
         }
     }
}
--------

and rustc complains with

--------
hello.rs:6:20: 6:51 error: type `std::rand::IsaacRng` does not
implement any method in scope named `shuffle`
hello.rs:6             let v = rand::rng().shuffle([1, 2, 3]);
--------

and a type inference error triggered by this part failing.  In
libstd/rand.rs, RngUtil seems to be defined for everything
implementing Rng, which IsaacRng does.  Is this a bug or is it some
change in the lookup?
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

To use the methods from a trait, it has to be in scope, so:

    use std::rand::{rng, RngUtil};

    fn main() {
        for ["Alice", "Bob", "Carol"].each |&name| {
            do spawn {
                let v = rng().shuffle([1, 2, 3]);
                for v.each |&num| {
                    print(fmt!("%s says: '%d'\n", name, num))
                }
            }
        }
    }

seems to work with my rustc (ba05af7 2013-06-20 22:28:52 -0700).

(The reason many other traits don't need to be explicitly imported
is that they are exported from std::prelude, which is implicitly added
as `use std::prelude::*;` at the top of every mod.)


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

Reply via email to