Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. enum Command {
  2. Right(i64),
  3. Up(i64),
  4. Move { x: i64, y: i64 },
  5. Print,
  6. }
  7.  
  8. fn main() {
  9. let mut cur = (0,0);
  10. let commands = &[Command::Move { x: 0, y: 0 },
  11. Command::Right(5),
  12. Command::Up(5),
  13. Command::Print,
  14. Command::Move { x: 10, y: 10 },
  15. Command::Print];
  16. for c in commands {
  17. match *c {
  18. Command::Right(x) => cur.0 += x,
  19. Command::Up(y) => cur.1 += y,
  20. Command::Move { x, y } => {
  21. cur.0 = x;
  22. cur.1 = y;
  23. }
  24. Command::Print => {
  25. println!("{:?}", cur);
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement