Skip to content

Instantly share code, notes, and snippets.

@brson
Created November 27, 2012 03:32
Show Gist options
  • Save brson/4152196 to your computer and use it in GitHub Desktop.
Save brson/4152196 to your computer and use it in GitHub Desktop.
trait MyNum {
static fn from_int(int) -> self;
}
pub trait NumExt: MyNum {}
fn greater_than_one<T:NumExt>() -> T { from_int(1) }
struct S {
v: int
}
impl S: MyNum {
static fn from_int(i: int) -> S {
S {
v: i
}
}
}
impl S: NumExt { }
fn main() {
let v: S = greater_than_one();
assert v.v == 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment