[][src]Crate rand_pwd

A simple demo of partital API:

use rand_pwd::{ RandPwd, ToRandPwd };
fn main() {
    let mut r_p = RandPwd::new(10, 2, 3); // For now, it's empty. Use method `join` to generate the password
    r_p.join();                           // Now `r_p` has some content, be kept in its `content` field
    println!("{}", r_p);                  // Print it on the screen
    // One possible output: 7$pA7yMCw=2DPGN
    // Or you can build from an existing `&str`
    let mut r_p = RandPwd::from("=tE)n5f`sidR>BV"); // 10 letters, 4 symbols, 1 number
    // You can rebuild a random password and with equivalent amount of letters, symbols and numbers. Like below
    println!("{}", r_p);
    // One possible output: qS`Xlyhpmg~"V8[
    // All the `String` and `&str` has implemented trait `ToRandPwd`
    // which means you can use method `to_randpwd` to convert a `String` or `&str` to `RandPwd`
    let mut r_p = "n4jpstv$dI,.z'K".to_randpwd().unwrap();
    // Panic! Has non-ASCII character(s)!
    // let mut r_p = RandPwd::from("🦀️🦀️🦀️");
    // let mut r_p = "🦀️🦀️🦀️".to_randpwd();

The UNIT field

The UNIT field is used to help process large number in concurrent way.

If you want to generate a huge random password with 1 million letters, symbols and numbers each, our program will accept such a sequence: [1M, 1M, 1M]. However, it takes up huge RAM(Because these numbers are represented in BigUint, kind of a Vec). And the procedure is single-threaded, you can only process them one by one.

My approach is to divide these large numbers into many small numbers, and then process these small numbers in parallel, so the small numbers here can be understood as UNIT. For 1M letters, we set 1K as the unit value, so [1M] = [1K, 1K, …, 1K] (1000 ones). And we just need to hand this sequence to rayon for processing. But the disadvantages are also obvious, if UNIT number is too small, like default value: 1, then capcity of the Vec is 1M at least! It will take up huge RAM (even all of them) and may harm your computer. In next version, there will be a smart UNIT value to end this problem.



struct RandPwd



A generic trait for converting a value to a RandPwd.