pub trait EnigmaBuilder {
// Required methods
fn rotors(self, first: u8, second: u8, third: u8) -> Result<EnigmaMachine>;
fn plugboard(self, plugboard: &str) -> Result<EnigmaMachine>;
fn reflector(self, reflector: &str) -> Result<EnigmaMachine>;
fn ring_settings(
self,
first: u8,
second: u8,
third: u8,
) -> Result<EnigmaMachine>;
fn ring_positions(
self,
first: u8,
second: u8,
third: u8,
) -> Result<EnigmaMachine>;
}
Expand description
A trait applied to anyhow::Result<EnigmaMachine>
that allows building an enigma machine and passing along errors if they occur.
Required Methods§
fn rotors(self, first: u8, second: u8, third: u8) -> Result<EnigmaMachine>
Sourcefn plugboard(self, plugboard: &str) -> Result<EnigmaMachine>
fn plugboard(self, plugboard: &str) -> Result<EnigmaMachine>
Sets the plugboard for the machine. The given plugboard should be a space-separated string of letter pairs. This is automatically
bidirectional, meaning the pair AY
will map A
to Y
and also Y
to A
.
§Parameters
plugboard
- A space-separated string of letter pairs, i.e.,AY BF QR UX GZ
.
§Returns
The machine builder with the given plugboard applied.
§Errors
If the machine builder passed to this is already an error, an error is returned immediately.
If the given plugboard contains duplicate letters, an error is returned.
If the given plugboard is not formatted as a space-separated list of letter pairs, an error is returned.
fn reflector(self, reflector: &str) -> Result<EnigmaMachine>
fn ring_settings( self, first: u8, second: u8, third: u8, ) -> Result<EnigmaMachine>
Sourcefn ring_positions(
self,
first: u8,
second: u8,
third: u8,
) -> Result<EnigmaMachine>
fn ring_positions( self, first: u8, second: u8, third: u8, ) -> Result<EnigmaMachine>
Sets the “ring positions” or “rotor positions” of the machine.
§Parameters
first
- The offset of the first rotor, in[1, 26]
.second
- The offset of the second rotor, in[1, 26]
.third
- The offset of the third rotor, in[1, 26]
.
§Returns
The machine builder with the given rotor positions applied.
§Errors
If the machine builder passed to this is already an error, an error is returned immediately.
If the given numbers are not all in [1, 26]
, an error is returned.