Skip to content

Instantly share code, notes, and snippets.

@eholk
Created July 17, 2012 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eholk/3126225 to your computer and use it in GitHub Desktop.
Save eholk/3126225 to your computer and use it in GitHub Desktop.
trait bar<T> {
fn get_bar() -> T;
}
fn foo<T, U: bar<T>>(b: U) -> T {
b.get_bar()
}
class cbar : bar<int> {
let x: int;
new(x: int) { self.x = x; }
fn get_bar() -> int {
self.x
}
}
fn main() {
let x: int = foo(cbar(5));
assert x == 5;
}
@eholk
Copy link
Author

eholk commented Jul 17, 2012

I get this compile error:

test.rs:18:17: 18:20 error: mismatched types: expected `bar<int>` but found `bar<'a>` (int vs type parameter)
test.rs:18     let x: int = foo(cbar(5));
                            ^~~
test.rs:18:17: 18:20 error: mismatched types: expected `'a` but found `int` (type parameter vs integral variable)
test.rs:18     let x: int = foo(cbar(5));
                            ^~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment