mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
21 lines
290 B
Rust
21 lines
290 B
Rust
|
trait bar<T> {
|
||
|
fn get_bar() -> T;
|
||
|
}
|
||
|
|
||
|
fn foo<T, U: bar<T>>(b: U) -> T {
|
||
|
b.get_bar()
|
||
|
}
|
||
|
|
||
|
struct cbar : bar<int> {
|
||
|
x: int;
|
||
|
new(x: int) { self.x = x; }
|
||
|
fn get_bar() -> int {
|
||
|
self.x
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let x: int = foo::<int, cbar>(cbar(5));
|
||
|
assert x == 5;
|
||
|
}
|