Re: [rust-dev] Front page example
Great, thanks, it works! Is there a way to invoke the shuffle() without bringing it explicitly into local scope, say via some verbose way that specifies the trait to be used? Ashish On Sat, Jun 22, 2013 at 11:00 PM, Huon Wilson dbau...@gmail.com wrote: 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 Rust-dev@mozilla.org 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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
[rust-dev] Front page example
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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] Front page example
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 Rust-dev@mozilla.org 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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev