Guest User

Untitled

a guest
Jun 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. struct A;
  2. struct B;
  3.  
  4. trait Walk {
  5. fn walk(&self);
  6. }
  7.  
  8. impl Walk for A {
  9. fn walk(&self) {
  10. println!("A walks");
  11. }
  12. }
  13.  
  14. impl Walk for B {
  15. fn walk(&self) {
  16. println!("B walks");
  17. }
  18. }
  19.  
  20. fn main() {
  21. let random = 42; // chosen randomly
  22. let person: Box<Walk> = if random > 39 { Box::new(A{}) } else { Box::new(B{}) };
  23. person.walk();
  24. }
Add Comment
Please, Sign In to add comment