Petr Novotnik
2014-09-16 19:41:30 UTC
Hello list,
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.
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>());
}
}
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 cannotfn main() {
let rng = &mut task_rng();
print_numbers(rng);
}
fn print_numbers(r: &mut Rng) {
for _ in range(0u, 10) {
println!("{}", r.gen::<uint>());
}
}
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
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.