randid

Crates.iorandid
lib.rsrandid
version0.1.0
sourcesrc
created_at2020-05-20 02:37:43.81391
updated_at2020-05-20 02:37:43.81391
descriptionRandid (pronounced like random but with `-id` instead of `-om`) is a minimalistic, web-safe library for generating customisable IDs for use in primarily web applications.
homepage
repositoryhttps://gitlab.com/owez/randid
max_upload_size
id243660
size6,822
Owen Griffiths (Owez)

documentation

README

Randid

Randid (pronounced like random but with -id instead of -om) is a minimalistic, web-safe library for generating customisable IDs for use in primarily web applications. The generated IDs are not guarenteed to be unique however!

Currently, this library has 2 main functions: randid_str() and randid_i32(). The former generates a random BASE62 (web-safe) string of a specified length and the latter creates a padded random integer of the specified length (like 00012 for a length of 5).

Examples

A random BASE62 string embedded as a url:

use randid::randid_str;

fn main() {
    let my_id = randid_str(5);

    println!("https://example.com/safeid/{}", my_id); // will provide a url-safe id like `bWk9D`, `yWvm3` or `POf3R`
}

Two padded random integers of 12 and 24 characters long respectively:

use randid::randid_i32;

fn main() {
    let padded_num_12 = randid_i32(12);
    let padded_num_24 = randid_i32(24);

    println!(
        "Guarenteed length of 12: {}, Guarenteed length of 24: {}",
        padded_num_12,
        padded_num_24
    );
}
Commit count: 4

cargo fmt