Struct MnemonicGenerator

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

A generator for creating memorable word combinations from predefined or custom word lists.

§Examples

use mnemonic_generator::MnemonicGenerator;

// Use the default generator
let generator = MnemonicGenerator::new();
let mnemonic = generator.generate().expect("Failed to generate mnemonic");
println!("Generated mnemonic: {}", mnemonic);

// Create a generator with custom words
let custom_generator = MnemonicGenerator::with_words(
    vec!["amazing".to_string(), "friendly".to_string(), "epic".to_string()],
    vec!["einstein".to_string(), "galileo".to_string()]
);
let custom_mnemonic = custom_generator.generate_with_separator("-")
    .expect("Failed to generate custom mnemonic");
println!("Custom mnemonic: {}", custom_mnemonic);

Implementations§

Source§

impl MnemonicGenerator

Creates a new MnemonicGenerator with a default set of words.

§Examples

use mnemonic_generator::MnemonicGenerator;

let generator = MnemonicGenerator::new();
let mnemonic = generator.generate().expect("Failed to generate mnemonic");
Source

pub fn new() -> Self

Create a new MnemonicGenerator with default words

Source

pub fn with_words(left_words: Vec<String>, right_words: Vec<String>) -> Self

Creates a MnemonicGenerator with custom word lists.

§Arguments
  • left_words - A vector of words to be used as the first part of the mnemonic
  • right_words - A vector of words to be used as the second part of the mnemonic
§Examples
use mnemonic_generator::MnemonicGenerator;

let generator = MnemonicGenerator::with_words(
    vec!["amazing".to_string(), "legend".to_string()],
    vec!["jordan".to_string(), "larry".to_string()]
);
let mnemonic = generator.generate().expect("Failed to generate mnemonic");
Source

pub fn generate(&self) -> Result<String, MnemonicError>

Generates a mnemonic using the default underscore separator.

§Errors

Returns MnemonicError::EmptyWordList if no words are available for generation

§Examples
use mnemonic_generator::MnemonicGenerator;

let generator = MnemonicGenerator::new();
match generator.generate() {
    Ok(mnemonic) => println!("Generated mnemonic: {}", mnemonic),
    Err(e) => eprintln!("Error generating mnemonic: {}", e)
}
Source

pub fn generate_with_separator( &self, separator: &str, ) -> Result<String, MnemonicError>

Generates a mnemonic using a custom separator.

§Arguments
  • separator - A string slice to be used between the two words
§Errors

Returns MnemonicError::EmptyWordList if no words are available for generation

§Examples
use mnemonic_generator::MnemonicGenerator;

let generator = MnemonicGenerator::new();
match generator.generate_with_separator("-") {
    Ok(mnemonic) => println!("Generated mnemonic: {}", mnemonic),
    Err(e) => eprintln!("Error generating mnemonic: {}", e)
}

Trait Implementations§

Source§

impl Default for MnemonicGenerator

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V