Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Created February 23, 2014 06:50
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 bvssvni/9168032 to your computer and use it in GitHub Desktop.
Save bvssvni/9168032 to your computer and use it in GitHub Desktop.
pub struct A {
a: int
}
pub struct B {
b: int
}
pub trait GetValue {
fn get_value(&self) -> int;
}
impl GetValue for A {
fn get_value(&self) -> int { self.a }
}
impl GetValue for B {
fn get_value(&self) -> int { self.b }
}
pub fn print_value<T: GetValue>(v: &T) {
println!("{}", v.get_value());
}
pub fn main() {
let a = A { a: 10 };
let b = B { b: 20 };
print_value(&a);
print_value(&b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment