From 57e0e51d7c695b07e86b34348bfc763aa6de7c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Palm=C3=B8?= Date: Sat, 18 Dec 2021 14:34:54 +0100 Subject: [PATCH] fixed some clippy errors --- src/main.rs | 2 +- src/plugboard.rs | 4 ++-- src/reflector.rs | 16 ++++++++-------- src/rotor.rs | 21 ++++++++++----------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index bbc5f46..0e0bbf7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,7 +159,7 @@ mod tests { let enigma_machine = Enigma::new(rotors, plugboard, reflector); let mut em1 = enigma_machine.clone(); - let mut em2 = enigma_machine.clone(); + let mut em2 = enigma_machine; println!("Encoding string"); let result = em1 diff --git a/src/plugboard.rs b/src/plugboard.rs index 561b0eb..7e0ae52 100644 --- a/src/plugboard.rs +++ b/src/plugboard.rs @@ -72,8 +72,8 @@ impl fmt::Display for Plugboard { let right_letter = *mapping; if left_letter != right_letter - && !pairs.get(&left_letter).is_some() - && !pairs.get(&right_letter).is_some() + && pairs.get(&left_letter).is_none() + && pairs.get(&right_letter).is_none() { pairs.insert(left_letter, right_letter); } diff --git a/src/reflector.rs b/src/reflector.rs index 2f4e714..48c9d83 100644 --- a/src/reflector.rs +++ b/src/reflector.rs @@ -49,14 +49,14 @@ impl Reflector { } } -const VARIANT_IDENTITY: &'static str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const VARIANT_BETA: &'static str = "LEYJVCNIXWPBQMDRTAKZGFUHOS"; -const VARIANT_GAMMA: &'static str = "FSOKANUERHMBTIYCWLQPZXVGJD"; -const VARIANT_A: &'static str = "EJMZALYXVBWFCRQUONTSPIKHGD"; -const VARIANT_B: &'static str = "YRUHQSLDPXNGOKMIEBFZCWVJAT"; -const VARIANT_C: &'static str = "FVPJIAOYEDRZXWGCTKUQSBNMHL"; -const VARIANT_B_THIN: &'static str = "ENKQAUYWJICOPBLMDXZVFTHRGS"; -const VARIANT_C_THIN: &'static str = "RDOBJNTKVEHMLFCWZAXGYIPSUQ"; +const VARIANT_IDENTITY: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const VARIANT_BETA: &str = "LEYJVCNIXWPBQMDRTAKZGFUHOS"; +const VARIANT_GAMMA: &str = "FSOKANUERHMBTIYCWLQPZXVGJD"; +const VARIANT_A: &str = "EJMZALYXVBWFCRQUONTSPIKHGD"; +const VARIANT_B: &str = "YRUHQSLDPXNGOKMIEBFZCWVJAT"; +const VARIANT_C: &str = "FVPJIAOYEDRZXWGCTKUQSBNMHL"; +const VARIANT_B_THIN: &str = "ENKQAUYWJICOPBLMDXZVFTHRGS"; +const VARIANT_C_THIN: &str = "RDOBJNTKVEHMLFCWZAXGYIPSUQ"; #[derive(Debug, Copy, Clone)] pub enum ReflectorVariant { diff --git a/src/rotor.rs b/src/rotor.rs index bbe6b7b..0b0506a 100644 --- a/src/rotor.rs +++ b/src/rotor.rs @@ -64,8 +64,7 @@ impl Rotor { self.mappings .iter() .enumerate() - .filter(|(_, l)| (**l - self.position) == letter) - .next() + .find(|(_, l)| (**l - self.position) == letter) .unwrap() .0, ) - self.position @@ -80,15 +79,15 @@ impl Rotor { } } -const IDENTITY: &'static str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const VARIANT_I: &'static str = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"; -const VARIANT_II: &'static str = "AJDKSIRUXBLHWTMCQGZNPYFVOE"; -const VARIANT_III: &'static str = "BDFHJLCPRTXVZNYEIWGAKMUSQO"; -const VARIANT_IV: &'static str = "ESOVPZJAYQUIRHXLNFTGKDCMWB"; -const VARIANT_V: &'static str = "VZBRGITYUPSDNHLXAWMJQOFECK"; -const VARIANT_VI: &'static str = "JPGVOUMFYQBENHZRDKASXLICTW"; -const VARIANT_VII: &'static str = "NZJHGRCXMYSWBOUFAIVLPEKQDT"; -const VARIANT_VIII: &'static str = "FKQHTLXOCBJSPDZRAMEWNIUYGV"; +const IDENTITY: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const VARIANT_I: &str = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"; +const VARIANT_II: &str = "AJDKSIRUXBLHWTMCQGZNPYFVOE"; +const VARIANT_III: &str = "BDFHJLCPRTXVZNYEIWGAKMUSQO"; +const VARIANT_IV: &str = "ESOVPZJAYQUIRHXLNFTGKDCMWB"; +const VARIANT_V: &str = "VZBRGITYUPSDNHLXAWMJQOFECK"; +const VARIANT_VI: &str = "JPGVOUMFYQBENHZRDKASXLICTW"; +const VARIANT_VII: &str = "NZJHGRCXMYSWBOUFAIVLPEKQDT"; +const VARIANT_VIII: &str = "FKQHTLXOCBJSPDZRAMEWNIUYGV"; #[non_exhaustive] #[derive(Debug, Copy, Clone)]