Skip to content

Instantly share code, notes, and snippets.

@dymk
Last active December 16, 2015 14:38
Show Gist options
  • Select an option

  • Save dymk/5449654 to your computer and use it in GitHub Desktop.

Select an option

Save dymk/5449654 to your computer and use it in GitHub Desktop.
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>();
}
// test.rs:20:1: 20:7 error: unresolved name
// test.rs:20 T::new()
// test ^~~~~~
// test.rs:20:1: 20:7 error: use of undeclared module `T`
// test.rs:20 T::new()
// test ^~~~~~
// test.rs:20:1: 20:7 error: unresolved name: `T::new`.
// test.rs:20 T::new()
// test ^~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment