Monkey
29 December 2023
This is a monkey.
pub trait Animal {
fn sound(&self);
}
pub struct Monkey {
name: String,
}
impl Monkey {
pub fn new(name: String) -> Monkey {
Monkey { name }
}
}
impl Animal for Monkey {
fn sound(&self) {
println!("{} says Ooh Ooh Ah Ah!", self.name);
}
}
fn main() {
let monkey = Monkey::new("Bob".to_string());
monkey.sound();
}