The following works though: let test: Foo = getOneOfThese();
hmm.... -- Ziad On Wed, May 15, 2013 at 12:12 PM, Ziad Hatahet <hata...@gmail.com> wrote: > I tried the above, but I got the following errors: > > $ rustc -v > rustc 0.6 > host: x86_64-unknown-linux-gnu > > $ cat static_type.rs > trait Newable { > fn new() -> Self; > } > > struct Foo(int); > > impl Newable for Foo { > fn new() -> Foo { > Foo(1) > } > } > > fn getOneOfThese<T: Newable>() -> T { > let x:T = Newable::new(); > x > } > > fn main() { > let test : Foo = getOneOfThese<Foo>(); > } > > $ rustc static_type.rs > static_type.rs:19:19: 19:36 error: binary operation < cannot be applied > to type `extern "Rust" fn() -> <V1>` > static_type.rs:19 let test : Foo = getOneOfThese<Foo>(); > ^~~~~~~~~~~~~~~~~ > static_type.rs:19:19: 19:32 error: cannot determine a type for this > bounded type parameter: unconstrained type > static_type.rs:19 let test : Foo = getOneOfThese<Foo>(); > ^~~~~~~~~~~~~ > > > > > -- > Ziad > > > On Sun, Apr 28, 2013 at 10:02 PM, Ashish Myles <marci...@gmail.com> wrote: > >> 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 <pwal...@mozilla.com> >> 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 >> > 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 mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev