Struct Morse

Source
pub struct Morse { /* private fields */ }
Expand description

§International standart Morse Code (default feature).

Implementations§

Source§

impl Morse

Source

pub fn from_text(text: &str) -> MorseResult<Morse>

Creates International Morse Code struct from text.

§Examples
use morse_lib::Morse;

let morse = Morse::from_text("sos").unwrap();

assert_eq!(morse.to_string(), ". . .   ⚊ ⚊ ⚊   . . .");
Source

pub fn from_bin(bin: &str) -> MorseResult<Morse>

Creates International Morse Code struct from binary.

§Examples
use morse_lib::Morse;

let morse = Morse::from_bin("101010001110111011100010101").unwrap();

assert_eq!(morse.to_string(), ". . .   ⚊ ⚊ ⚊   . . .");
Source

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_text("sos").unwrap();
morse.dot_as("🔥");

assert_eq!(morse.to_string(), "🔥 🔥 🔥   ⚊ ⚊ ⚊   🔥 🔥 🔥");
Source

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_text("sos").unwrap();
morse.line_as("➖");

assert_eq!(morse.to_string(), ". . .   ➖ ➖ ➖   . . .");
Source

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_text("s o").unwrap();
morse.whitespace_as("🚧");

assert_eq!(morse.to_string(), ". . .   🚧   ⚊ ⚊ ⚊");
Source

pub fn to_beep(&self)

Play sound that represent Morse Code.

Only available if “audio” feature is enabled.

Source

pub fn frequency(&mut self, frequency: f32)

Set sound frequency in MHz.

Only available if “audio” feature is enabled.

§Examples
use morse_lib::Morse;

let mut morse = Morse::from_text("s o").unwrap();
morse.frequency(643.0);
Source

pub fn play_speed(&mut self, speed: f32)

Set sound speed.

Only available if “audio” feature is enabled.

  • ‘1’ - normal speed
  • ‘> 1’ - faster
  • ‘< 1’ - slower
§Examples
use morse_lib::Morse;

let mut morse = Morse::from_text("s o").unwrap();
morse.play_speed(2.0);
Source

pub fn to_bin_str(&self) -> String

Creates binary-formatted Morse Code.

§Examples
use morse_lib::Morse;

let morse = Morse::from_text("sos").unwrap();

assert_eq!(morse.to_bin_str(), "101010001110111011100010101");
Source

pub fn to_text(&self) -> String

Convert Morse Code back to text.

§Examples
use morse_lib::Morse;

let morse = Morse::from_bin("101010001110111011100010101").unwrap();
let text = morse.to_text();

assert_eq!(text, "sos");
Source

pub fn iter(&self) -> MorseIterator<'_>

Now we can iterate:

use morse_lib::Morse;

let morse = Morse::from_text("sos").unwrap();
for char in morse.iter() {
    println!("{}", char);
}

Trait Implementations§

Source§

impl Clone for Morse

Source§

fn clone(&self) -> Morse

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Morse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Morse

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Index<usize> for Morse

Source§

type Output = MorseChar

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IntoIterator for Morse

Source§

fn into_iter(self) -> MorseIntoIterator

use morse_lib::Morse;

let morse = Morse::from_text("sos").unwrap();
for char in morse {
println!("{}", char);
}
Source§

type Item = MorseChar

The type of the elements being iterated over.
Source§

type IntoIter = MorseIntoIterator

Which kind of iterator are we turning this into?
Source§

impl PartialEq for Morse

Source§

fn eq(&self, other: &Morse) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TMorse for Morse

Source§

fn parse_text(&mut self, text: &str) -> MorseResult<()>

Parse text into Morse Code.

Source§

fn parse_bin(&mut self, bin: &str) -> MorseResult<()>

Parse binary into Morse Code.

Source§

fn len(&self) -> usize

Morse Code string length.
Source§

fn remove(&mut self, idx: usize) -> MorseChar

Remove Morse Code character by index.
Source§

impl ToString for Morse

Source§

fn to_string(&self) -> String

Return String value of Morse Code.

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,