Mnemonic

Struct Mnemonic 

Source
pub struct Mnemonic { /* private fields */ }

Implementations§

Source§

impl Mnemonic

Source

pub fn new(lang: Language, mnemonic_type: MnemonicType) -> Mnemonic

Wrapper for .generator() function, created to handle errors

Examples found in repository?
examples/generate_mnemonics.rs (line 19)
3fn main() {
4    /*
5        Demonstrating the use of the bip39-rusty library to generate a BIP39 mnemonic phrase.
6
7        The `Mnemonic` struct expects:
8            - Language (e.g., Language::English)
9            - MnemonicType (e.g., Bits128 or Bits256)
10
11        Once created, you can use the following getter method:
12            - .mnemonic_phrase() => Returns the generated mnemonic phrase as a Vec<String>.
13
14        Note: If any internal error occurs during mnemonic generation,
15              the library will return a default Mnemonic with 256 bits and Language::English type.
16    */
17
18    // Create a new mnemonic
19    let mnemonic = Mnemonic::new(Language::English, MnemonicType::Bits256);
20
21    // Display the mnemonic phrases
22    println!("Generated Mnemonic Phrase: {:?}", mnemonic.mnemonic_phrase());
23
24    // validate the checksum
25    let validation_result = mnemonic.validate_checksum();
26
27    match validation_result {
28        Ok(_value) => {
29            println!("Its valid")
30        }
31        Err(_e) => {
32            println!("Not valid")
33        }
34    }
35
36}
Source

pub fn validate_checksum(&self) -> Result<bool, MnemonicError>

Examples found in repository?
examples/generate_mnemonics.rs (line 25)
3fn main() {
4    /*
5        Demonstrating the use of the bip39-rusty library to generate a BIP39 mnemonic phrase.
6
7        The `Mnemonic` struct expects:
8            - Language (e.g., Language::English)
9            - MnemonicType (e.g., Bits128 or Bits256)
10
11        Once created, you can use the following getter method:
12            - .mnemonic_phrase() => Returns the generated mnemonic phrase as a Vec<String>.
13
14        Note: If any internal error occurs during mnemonic generation,
15              the library will return a default Mnemonic with 256 bits and Language::English type.
16    */
17
18    // Create a new mnemonic
19    let mnemonic = Mnemonic::new(Language::English, MnemonicType::Bits256);
20
21    // Display the mnemonic phrases
22    println!("Generated Mnemonic Phrase: {:?}", mnemonic.mnemonic_phrase());
23
24    // validate the checksum
25    let validation_result = mnemonic.validate_checksum();
26
27    match validation_result {
28        Ok(_value) => {
29            println!("Its valid")
30        }
31        Err(_e) => {
32            println!("Not valid")
33        }
34    }
35
36}
Source

pub fn mnemonic_phrase(&self) -> &Vec<String>

Getter for the mnemonic phrase.

Examples found in repository?
examples/generate_mnemonics.rs (line 22)
3fn main() {
4    /*
5        Demonstrating the use of the bip39-rusty library to generate a BIP39 mnemonic phrase.
6
7        The `Mnemonic` struct expects:
8            - Language (e.g., Language::English)
9            - MnemonicType (e.g., Bits128 or Bits256)
10
11        Once created, you can use the following getter method:
12            - .mnemonic_phrase() => Returns the generated mnemonic phrase as a Vec<String>.
13
14        Note: If any internal error occurs during mnemonic generation,
15              the library will return a default Mnemonic with 256 bits and Language::English type.
16    */
17
18    // Create a new mnemonic
19    let mnemonic = Mnemonic::new(Language::English, MnemonicType::Bits256);
20
21    // Display the mnemonic phrases
22    println!("Generated Mnemonic Phrase: {:?}", mnemonic.mnemonic_phrase());
23
24    // validate the checksum
25    let validation_result = mnemonic.validate_checksum();
26
27    match validation_result {
28        Ok(_value) => {
29            println!("Its valid")
30        }
31        Err(_e) => {
32            println!("Not valid")
33        }
34    }
35
36}

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

Source§

type Output = T

Should always be Self
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