Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. fn main() {
  2. #[derive(Copy, Clone, PartialEq, Debug)]
  3. enum SearchDirection {
  4. Left = 0,
  5. Right,
  6. }
  7. impl From<u8> for SearchDirection {
  8. fn from(d: u8) -> Self {
  9. match d {
  10. 1 => SearchDirection::Right,
  11. _ => SearchDirection::Left,
  12. }
  13. }
  14. }
  15. impl SearchDirection {
  16. const MAX: u8 = 2;
  17. pub fn flip(&mut self) -> Self {
  18. std::mem::replace(self, ((*self as u8 + 1) % Self::MAX).into())
  19. }
  20. }
  21.  
  22. let mut search = SearchDirection::Left;
  23. for i in 0..10 {
  24. eprintln!("{:?}", search.flip());
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement