pub struct Morse { /* private fields */ }Expand description
§Main library struct.
All magic going here
Implementations§
Source§impl Morse
impl Morse
Sourcepub fn new(
language: String,
from_char: fn(_: char) -> MorseResult<Vec<MorseUnit>>,
into_char: fn(_: Vec<MorseUnit>) -> MorseResult<char>,
) -> Morse
pub fn new( language: String, from_char: fn(_: char) -> MorseResult<Vec<MorseUnit>>, into_char: fn(_: Vec<MorseUnit>) -> MorseResult<char>, ) -> Morse
Creates extended Morse Code struct.
§Examples
use morse_lib::{Morse, MorseUnit, MorseError, MorseResult};
use MorseUnit::{Dot, Line, Whitespace};
fn from_char(letter: char) -> MorseResult<Vec<MorseUnit>>{
match letter {
'a' => Ok(vec![Dot, Line]),
'б' => Ok(vec![Line, Dot, Dot, Dot]),
'в' => Ok(vec![Dot, Line, Line]),
'г' => Ok(vec![Dot, Dot, Dot, Dot]),
' ' => Ok(vec![Whitespace]),
_ => Err(MorseError::InvalidChar)
}
}
fn into_char(letter: Vec<MorseUnit>) -> MorseResult<char> {
if letter.len() == 1 && letter[0] == Whitespace {
return Ok(' ');
} else if letter.len() == 2 && letter[0] == Dot && letter[1] == Line {
return Ok('а')
} else if letter.len() == 3 && letter[0] == Dot && letter[1] == Line && letter[2] == Line {
return Ok('в');
} else if letter.len() == 4 {
if letter[0] == Line && letter[1] == Dot && letter[2] == Dot && letter[3] == Dot {
return Ok('б');
} else {
return Ok('г');
}
} else {
Err(MorseError::InvalidMorseSequence)
}
}
let morse = Morse::new("Ukrainian".to_string(), from_char, into_char);Sourcepub fn from_int_text(text: &str) -> MorseResult<Morse>
pub fn from_int_text(text: &str) -> MorseResult<Morse>
Creates International Morse Code struct from text.
§Examples
use morse_lib::Morse;
let morse = Morse::from_int_text("sos").unwrap();
assert_eq!(
morse.to_string(),
". . . ⚊ ⚊ ⚊ . . ."
);Sourcepub fn parse_text(&mut self, text: &str) -> MorseResult<()>
pub fn parse_text(&mut self, text: &str) -> MorseResult<()>
Parse text into Morse Code.
Sourcepub fn from_int_bin(bin: &str) -> MorseResult<Morse>
pub fn from_int_bin(bin: &str) -> MorseResult<Morse>
Creates International Morse Code struct from binary.
§Examples
use morse_lib::Morse;
let morse = Morse::from_int_bin("101010001110111011100010101").unwrap();
assert_eq!(
morse.to_string(),
". . . ⚊ ⚊ ⚊ . . ."
);Sourcepub fn parse_bin(&mut self, bin: &str) -> MorseResult<()>
pub fn parse_bin(&mut self, bin: &str) -> MorseResult<()>
Parse binary into Morse Code.
Sourcepub fn get_language(&self) -> String
pub fn get_language(&self) -> String
Return String value that contains stored language label.
Sourcepub fn dot_as(&mut self, alias: &str)
pub fn dot_as(&mut self, alias: &str)
Creates alias for dot in output string.
§Examples
use morse_lib::Morse;
let mut morse = Morse::from_int_text("sos").unwrap();
morse.dot_as("🔥");
assert_eq!(
morse.to_string(),
"🔥 🔥 🔥 ⚊ ⚊ ⚊ 🔥 🔥 🔥"
);Sourcepub fn line_as(&mut self, alias: &str)
pub fn line_as(&mut self, alias: &str)
Creates alias for line in output string.
§Examples
use morse_lib::Morse;
let mut morse = Morse::from_int_text("sos").unwrap();
morse.line_as("➖");
assert_eq!(
morse.to_string(),
". . . ➖ ➖ ➖ . . ."
);Sourcepub fn whitespace_as(&mut self, alias: &str)
pub fn whitespace_as(&mut self, alias: &str)
Creates alias for whitespace in output string.
§Examples
use morse_lib::Morse;
let mut morse = Morse::from_int_text("s o").unwrap();
morse.whitespace_as("🚧");
assert_eq!(
morse.to_string(),
". . . 🚧 ⚊ ⚊ ⚊"
);Sourcepub fn frequency(&mut self, frequency: f32)
pub fn frequency(&mut self, frequency: f32)
Set sound frequency in MHz.
§Examples
use morse_lib::Morse;
let mut morse = Morse::from_int_text("s o").unwrap();
morse.frequency(643.0);Sourcepub fn play_speed(&mut self, speed: f32)
pub fn play_speed(&mut self, speed: f32)
Set sound speed. 1 - normal speed
1 - faster < 1 - slower
§Examples
use morse_lib::Morse;
let mut morse = Morse::from_int_text("s o").unwrap();
morse.play_speed(2.0);Sourcepub fn to_bin_str(&self) -> String
pub fn to_bin_str(&self) -> String
Creates binary-formatted Morse Code.
§Examples
use morse_lib::Morse;
let morse = Morse::from_int_text("sos").unwrap();
assert_eq!(
morse.to_bin_str(),
"101010001110111011100010101"
);Trait Implementations§
Source§impl IntoIterator for Morse
impl IntoIterator for Morse
impl StructuralPartialEq for Morse
Auto Trait Implementations§
impl Freeze for Morse
impl RefUnwindSafe for Morse
impl Send for Morse
impl Sync for Morse
impl Unpin for Morse
impl UnwindSafe for Morse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)