On 4/23/13 10:22 PM, Dylan Knutson wrote:
Hello everyone,
I've been pretty enamored with Rust the past few weeks, and I'm loving
the language so far. However, there is one feature of generics that
doesn't seem to exist in the language, which is being able to call
static methods on type parameters (provided that the type parameter can
be guaranteed to implement it). I'm not all that familiar with
the technical details of the language, so I'm not sure if this is
impossible, or just decided against for some reason. I'm not even sure
if I'm using the terminology correctly, so let me illustrate with some
code:

trait Newable {
fn new() -> Self;
}

struct Foo(int);
impl Newable for Foo {
fn new() -> Foo {
return Foo(1);
}
}

fn getOneOfThese<T : Newable>() -> T {
T::new()
}

fn main() {
let test = getOneOfThese<Foo>();
}

Inside `getOneOfThese`, try this:

    let x: T = Newable::new();

Patrick

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to