idnano

Crates.ioidnano
lib.rsidnano
version0.8.4
sourcesrc
created_at2022-11-18 04:55:15.869417
updated_at2022-11-21 03:55:00.034775
descriptiona simple nanoid generator
homepagehttps://github.com/ledao/nanoid
repository
max_upload_size
id717645
size11,169
Ledao (ledao)

documentation

https://github.com/ledao/nanoid

README

nanoid

nanoid is a rust version of nanoid, implemented by myself(not official).

Usage

Open Cargo.toml file, and add dependencies.

[dependencies]
idnano = "0.8.4"

Use macro to generate id.

use idnano::*;

fn main() {
    let id: String = id!();
    println!("id: {}", id); //id: g6-O7ul2xfd810SeN7Fjd for example.

    let id_10: String = id!(10);
    println!("id: {}", id_10); // id: twMwyPTtd1 for example.

    let id_alphabet: String = id!(10, "1234567890".as_bytes());
    println!("id: {}", id_alphabet); // id: 6472071276 for example.
}

Use normal function to generate ids.

Generate a default nano id.

use idnano;

fn main() {
    let id: String = idnano::new();
    println!("id: {}", id); // id: g6-O7ul2xfd810SeN7Fjd for example.
}

Generate a customized nano id.

use idnano;

fn main() {
    let alphabet = "1234567890".as_bytes();
    let size = 10;
    let id: String = idnano::generate_string(alphabet, size);
    println!("id: {}", id); // id: 0548300922 for example.
}

Thanks to

Commit count: 0

cargo fmt