Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct A;
- struct B;
- trait Walk {
- fn walk(&self);
- }
- impl Walk for A {
- fn walk(&self) {
- println!("A walks");
- }
- }
- impl Walk for B {
- fn walk(&self) {
- println!("B walks");
- }
- }
- fn main() {
- let random = 42; // chosen randomly
- let person: Box<Walk> = if random > 39 { Box::new(A{}) } else { Box::new(B{}) };
- person.walk();
- }
Add Comment
Please, Sign In to add comment