Hello list,
I've got this small program:
use std::rand::{Rng, task_rng};
fn main() {
let rng = &mut task_rng();
print_numbers(rng);
}
fn print_numbers(r: &mut Rng) {
for _ in range(0u, 10) {
println!("{}", r.gen::<uint>());
}
}
generating me this compiler error:
rustc random.rs
random.rs:10:24: 10:39 error: cannot call a generic method through an object
[E0039]
random.rs:10 println!("{}", r.gen::<uint>());
^~~~~~~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
random.rs:10:9: 10:41 note: expansion site
error: aborting due to previous error
I think the reason for the error message is because the compiler cannot
statically dispatch the call. Correct?
If so, I wonder what the motivation is for having generic methods in
traits which themselves are not generified. If I understand it
correctly, there's no chance invoking such a generic method through a
trait type.
Pete.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev