1mod substitution;
2
3use substitution::{MorseChunk, itu_substitution, gerke_substitution};
4
5pub type Plaintext = String;
6pub type Morse = String;
7
8pub enum MorseType {
10 ITU, Morse, Gerke }
14
15fn with_substitute(word: &Plaintext, substitue_method: fn(char) -> MorseChunk) -> Morse {
17 word.to_uppercase().chars().into_iter().map(|chr|{ substitue_method(chr) })
18 .collect::<Vec<MorseChunk>>().join("")
19}
20
21pub trait MorseSubstitution {
22 fn to_morse(&self, morse_type: MorseType) -> Morse;
23}
24
25impl MorseSubstitution for Plaintext {
26 fn to_morse(&self, morse_type: MorseType) -> Morse {
27 match morse_type {
28 MorseType::ITU => with_substitute(&self, itu_substitution),
29 MorseType::Gerke => with_substitute(&self, gerke_substitution),
30 _ => panic!("Other methods than ITU not implemented. Type")
31 }
32 }
33}