diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -17,6 +17,10 @@ extern { #[wasm_bindgen] pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool) -> String { + if len == 0 ||!lower && !upper && !number && !special { + return "".to_string(); + } + let mut upper_charset: Vec<char> = String::from("ABCDEFGHIJKLMNOPQRSTUVWXYZ").chars().collect(); let mut lower_charset: Vec<char> = String::from("abcdefghijklmnopqrstuvwxyz").chars().collect(); let mut number_charset: Vec<char> = String::from("1234567890").chars().collect(); @@ -41,7 +45,6 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo result.append(&mut special_charset); } - (0..len) .map(|_| { let idx = rng.gen_range(0..result.len()); |