Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- #[derive(Copy, Clone, PartialEq, Debug)]
- enum SearchDirection {
- Left = 0,
- Right,
- }
- impl From<u8> for SearchDirection {
- fn from(d: u8) -> Self {
- match d {
- 1 => SearchDirection::Right,
- _ => SearchDirection::Left,
- }
- }
- }
- impl SearchDirection {
- const MAX: u8 = 2;
- pub fn flip(&mut self) -> Self {
- std::mem::replace(self, ((*self as u8 + 1) % Self::MAX).into())
- }
- }
- let mut search = SearchDirection::Left;
- for i in 0..10 {
- eprintln!("{:?}", search.flip());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement