Ha! I asked the same question when I first started. I wouldn't be surprised if this is a common cause of confusion for people coming from C++ and that name resolution family. Perhaps notes regarding this could be added to https://github.com/mozilla/rust/wiki/Rust-for-CXX-programmers ?
Ashish On Wed, Apr 24, 2013 at 3:58 AM, Patrick Walton <[email protected]> wrote: > 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 > [email protected] > https://mail.mozilla.org/listinfo/rust-dev _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
