Skip to content

Instantly share code, notes, and snippets.

@balajisivaraman
Created May 13, 2018 15:02
Show Gist options
  • Save balajisivaraman/0cfded4cab727e57e6663b3cc8da14f8 to your computer and use it in GitHub Desktop.
Save balajisivaraman/0cfded4cab727e57e6663b3cc8da14f8 to your computer and use it in GitHub Desktop.
Rust 1.26 Sample
trait Animal {
fn walk(&self);
}
struct Dog {
pub name: String
}
impl Animal for Dog {
fn walk(&self) {
println!("dog walks: {}", self.name);
}
}
struct Cat {
pub name: String
}
impl Animal for Cat {
fn walk(&self) {
println!("cat walks: {}", self.name);
}
}
fn test(cat: Cat) -> impl Animal {
if cat.name == "Fussy" {
cat
} else {
Cat { name: "Scooby".to_string() }
}
}
fn main() {
// let dog = Dog { name: "Snowy".to_string() };
// let testedDog = test(dog);
// testedDog.walk();
let cat = Cat { name: "Fussy".to_string() };
let testedCat = test(cat);
testedCat.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