mnemonic-generator

Crates.iomnemonic-generator
lib.rsmnemonic-generator
version0.1.1
created_at2024-12-15 19:06:32.571281+00
updated_at2024-12-15 19:08:25.098115+00
descriptionA library to generate Docker-like mnemonics.
homepage
repositoryhttps://github.com/akoken/mnemonic-generator
max_upload_size
id1484349
size72,008
Abdurrahman Alp Köken (akoken)

documentation

https://docs.rs/mnemonic-generator

README

Mnemonic Generator

A lightweight Rust library for generating Docker-like mnemonics.

Installation

Add the following to your Cargo.toml:

[dependencies]
mnemonic-generator = "0.1.0"

Usage

Basic Usage

use mnemonic_generator::MnemonicGenerator;

fn main() {
    // Create a generator with default words
    let generator = MnemonicGenerator::new();

    // Generate a mnemonic with default underscore separator
    match generator.generate() {
        Ok(mnemonic) => println!("Generated mnemonic: {}", mnemonic),
        Err(e) => eprintln!("Error: {}", e)
    }
}

Custom Word Lists

use mnemonic_generator::MnemonicGenerator;

fn main() {
    // Create a generator with custom words
    let generator = MnemonicGenerator::with_words(
        vec!["amazing".to_string(), "legend".to_string()],
        vec!["jordan".to_string(), "larry".to_string()]
    );

    // Generate a mnemonic with a custom separator
    match generator.generate_with_separator("-") {
        Ok(mnemonic) => println!("Custom mnemonic: {}", mnemonic),
        Err(e) => eprintln!("Error: {}", e)
    }
}

Error Handling

The library provides a MnemonicError enum to handle potential generation errors:

  • EmptyWordList: Occurs when no words are available for generating a mnemonic

License

[MIT License]

Commit count: 15

cargo fmt