Skip to content

Instantly share code, notes, and snippets.

@balajisivaraman
Created May 13, 2018 15:03
Show Gist options
  • Save balajisivaraman/5b8885503be27ded5393678be5fb2a5d to your computer and use it in GitHub Desktop.
Save balajisivaraman/5b8885503be27ded5393678be5fb2a5d to your computer and use it in GitHub Desktop.
Rust 1.25 Sample
trait Animal {
fn walk(&self);
}
struct Dog {
name: String
}
impl Animal for Dog {
fn walk(&self) {
println!("dog walks: {}", self.name);
}
}
struct Cat {
name: String
}
impl Animal for Cat {
fn walk(&self) {
println!("cat walks: {}", self.name);
}
}
fn test<A: 'static + Animal>(animal: A) -> Box<Animal> {
Box::new(animal)
}
fn main() {
let animal = Dog { name: "Snowy".to_string() };
let boxed = test(animal);
(*boxed).walk();
}
fn test_num<'a>(a: &'a i32, b: &'a i32) -> &'a i32 {
a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment