From: Grégory Burri Date: Fri, 20 Dec 2019 07:58:30 +0000 (+0100) Subject: Replace an 'if' by a 'match' X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=e4a67094db0bdd8c213afe18c2689ad5ffba039f;p=advent_of_code_2019.git Replace an 'if' by a 'match' --- diff --git a/src/day13.rs b/src/day13.rs index 169f4d8..edf2132 100644 --- a/src/day13.rs +++ b/src/day13.rs @@ -1,4 +1,5 @@ use super::intcode; +use std::cmp::Ordering; use std::convert::TryFrom; use itertools::Itertools; use num_enum::TryFromPrimitive; @@ -52,12 +53,10 @@ impl intcode::IO for State { self.paddle_position_x = self.buffer[0]; } self.joystick = - if self.paddle_position_x > self.ball_position_x { - -1 - } else if self.paddle_position_x < self.ball_position_x { - 1 - } else { - 0 + match self.paddle_position_x.cmp(&self.ball_position_x) { + Ordering::Greater => -1, + Ordering::Less => 1, + Ordering::Equal => 0 }; } self.buffer.clear();