mini_enigma/components/
reflector.rs1use crate::utils::UNIT_LETTER_MAP;
2
3use super::utils::{string_to_letter_map, Letter, LetterMapping};
4
5#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
6pub struct Reflector {
8 wiring: LetterMapping,
9}
10
11impl Default for Reflector {
12 fn default() -> Self {
13 Reflector {
14 wiring: UNIT_LETTER_MAP,
15 }
16 }
17}
18
19impl Reflector {
20 #[must_use]
22 pub const fn from_static_str(string: &'static str) -> Reflector {
23 Reflector {
24 wiring: string_to_letter_map(string),
25 }
26 }
27}
28
29#[allow(missing_docs)]
30pub const REFLECTOR_A: Reflector = Reflector::from_static_str("EJMZALYXVBWFCRQUONTSPIKHGD");
31
32#[allow(missing_docs)]
33pub const REFLECTOR_B: Reflector = Reflector::from_static_str("YRUHQSLDPXNGOKMIEBFZCWVJAT");
34
35#[allow(missing_docs)]
36pub const REFLECTOR_C: Reflector = Reflector::from_static_str("FVPJIAOYEDRZXWGCTKUQSBNMHL");
37
38#[allow(missing_docs)]
39pub const REFLECTOR_B_THIN: Reflector = Reflector::from_static_str("ENKQAUYWJICOPBLMDXZVFTHRGS");
40
41#[allow(missing_docs)]
42pub const REFLECTOR_C_THIN: Reflector = Reflector::from_static_str("RDOBJNTKVEHMLFCWZAXGYIPSUQ");
43
44impl core::ops::Index<Letter> for Reflector {
45 type Output = Letter;
46
47 fn index(&self, index: Letter) -> &Self::Output {
48 &self.wiring[index]
49 }
50}