mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-05 14:37:37 +00:00
25 lines
350 B
Rust
25 lines
350 B
Rust
![]() |
trait MyNum {
|
||
|
static fn from_int(int) -> self;
|
||
|
}
|
||
|
|
||
|
pub trait NumExt: MyNum { }
|
||
|
|
||
|
struct S { v: int }
|
||
|
|
||
|
impl S: MyNum {
|
||
|
static fn from_int(i: int) -> S {
|
||
|
S {
|
||
|
v: i
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl S: NumExt { }
|
||
|
|
||
|
fn greater_than_one<T:NumExt>() -> T { from_int(1) }
|
||
|
|
||
|
fn main() {
|
||
|
let v: S = greater_than_one();
|
||
|
assert v.v == 1;
|
||
|
}
|