warlocks_cauldron/providers/
code.rs1use super::dependencies::*;
2
3
4pub struct Code;
6
7impl Code {
8 pub fn locale_code() -> &'static str {
12 get_random_element(LOCALE_CODES.iter())
13 }
14
15 pub fn issn() -> String {
19 custom_code("####-####", '@', '#')
20 }
21
22 pub fn isbn(fmt: Option<ISBNFormat>, locale: Locale) -> String {
30 let data = locale.get_data();
31
32 let fmt_key = validate_enum(fmt, None);
33
34 let mask = ISBN_MASKS.get(fmt_key).expect("ISBN_MASKS doesnt have current ISBNFormat!")
35 .replace("{0}", ISBN_GROUPS.get(&data.lang_code[..]).unwrap_or_else(|| ISBN_GROUPS.get("default").unwrap()));
36
37 custom_code(&mask, '@', '#')
38 }
39
40 pub fn ean(fmt: Option<EANFormat>) -> String {
47 custom_code(EAN_MASKS.get(validate_enum(fmt, None)).expect("EAN_MASKS doesnt have current EANFormat!"), '@', '#')
48 }
49
50 pub fn imei() -> String {
54 let num = format!("{}{}", get_random_element(IMEI_TACS.iter()), randint(100000, 999999));
55 format!("{num}{}", luhn::checksum(num.as_bytes()))
56 }
57
58 pub fn pin() -> String {
62 custom_code("####", '@', '#')
63 }
64}