Struct bip39::Mnemonic[][src]

pub struct Mnemonic { /* fields omitted */ }
Expand description

A mnemonic code.

The core::str::FromStr implementation will try to determine the language of the mnemonic from all the supported languages. (Languages have to be explicitly enabled using the Cargo features.)

Supported number of words are 12, 18 and 24.

Implementations

impl Mnemonic[src]

pub fn from_entropy_in(
    language: Language,
    entropy: &[u8]
) -> Result<Mnemonic, Error>
[src]

Create a new Mnemonic in the specified language from the given entropy. Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.

pub fn from_entropy(entropy: &[u8]) -> Result<Mnemonic, Error>[src]

Create a new English Mnemonic from the given entropy. Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.

pub fn generate_in_with<R>(
    rng: &mut R,
    language: Language,
    word_count: usize
) -> Result<Mnemonic, Error> where
    R: RngCore + CryptoRng
[src]

Generate a new Mnemonic in the given language with the given randomness source. For the different supported word counts, see documentation on Mnemonic.

Example:

extern crate rand;
extern crate bip39;

use bip39::{Mnemonic, Language};

let mut rng = rand::thread_rng();
let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();

pub fn language(&self) -> Language[src]

Get the language of the Mnemonic.

pub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone + '_[src]

Get an iterator over the words.

pub fn language_of<S: AsRef<str>>(mnemonic: S) -> Result<Language, Error>[src]

Determine the language of the mnemonic.

NOTE: This method only guarantees that the returned language is the correct language on the assumption that the mnemonic is valid. It does not itself validate the mnemonic.

Some word lists don’t guarantee that their words don’t occur in other word lists. In the extremely unlikely case that a word list can be interpreted in multiple languages, an Error::AmbiguousLanguages is returned, containing the possible languages.

pub fn parse_in_normalized(
    language: Language,
    s: &str
) -> Result<Mnemonic, Error>
[src]

Parse a mnemonic in normalized UTF8 in the given language.

pub fn parse_normalized(s: &str) -> Result<Mnemonic, Error>[src]

Parse a mnemonic in normalized UTF8.

pub fn parse_in<'a, S: Into<Cow<'a, str>>>(
    language: Language,
    s: S
) -> Result<Mnemonic, Error>
[src]

Parse a mnemonic in the given language.

pub fn parse<'a, S: Into<Cow<'a, str>>>(s: S) -> Result<Mnemonic, Error>[src]

Parse a mnemonic and detect the language from the enabled languages.

pub fn word_count(&self) -> usize[src]

Get the number of words in the mnemonic.

pub fn to_seed_normalized(&self, normalized_passphrase: &str) -> [u8; 64][src]

Convert to seed bytes with a passphrase in normalized UTF8.

pub fn to_seed<'a, P: Into<Cow<'a, str>>>(&self, passphrase: P) -> [u8; 64][src]

Convert to seed bytes.

pub fn to_entropy_array(&self) -> ([u8; 33], usize)[src]

Convert the mnemonic back to the entropy used to generate it. The return value is a byte array and the size. Use Mnemonic::to_entropy (needs std) to get a Vec.

pub fn to_entropy(&self) -> Vec<u8>[src]

Convert the mnemonic back to the entropy used to generate it.

Trait Implementations

impl Clone for Mnemonic[src]

fn clone(&self) -> Mnemonic[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Mnemonic[src]

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

Formats the value using the given formatter. Read more

impl<'de> Deserialize<'de> for Mnemonic[src]

fn deserialize<D>(deserializer: D) -> Result<Mnemonic, D::Error> where
    D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for Mnemonic[src]

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

Formats the value using the given formatter. Read more

impl FromStr for Mnemonic[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Mnemonic, Error>[src]

Parses a string s to return a value of this type. Read more

impl Hash for Mnemonic[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl Ord for Mnemonic[src]

fn cmp(&self, other: &Mnemonic) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Mnemonic> for Mnemonic[src]

fn eq(&self, other: &Mnemonic) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Mnemonic) -> bool[src]

This method tests for !=.

impl PartialOrd<Mnemonic> for Mnemonic[src]

fn partial_cmp(&self, other: &Mnemonic) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'de> Serialize for Mnemonic[src]

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
    S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl Eq for Mnemonic[src]

impl StructuralEq for Mnemonic[src]

impl StructuralPartialEq for Mnemonic[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]