1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use super::dependencies::*;
pub struct Code;
impl Code {
pub fn locale_code() -> &'static str {
get_random_element(LOCALE_CODES.iter())
}
pub fn issn() -> String {
custom_code("####-####", '@', '#')
}
pub fn isbn(fmt: Option<ISBNFormat>, locale: Locale) -> String {
let data = locale.get_data();
let fmt_key = validate_enum(fmt, None);
let mask = ISBN_MASKS.get(fmt_key).expect("ISBN_MASKS doesnt have current ISBNFormat!")
.replace("{0}", ISBN_GROUPS.get(&data.lang_code[..]).unwrap_or_else(|| ISBN_GROUPS.get("default").unwrap()));
custom_code(&mask, '@', '#')
}
pub fn ean(fmt: Option<EANFormat>) -> String {
custom_code(EAN_MASKS.get(validate_enum(fmt, None)).expect("EAN_MASKS doesnt have current EANFormat!"), '@', '#')
}
pub fn imei() -> String {
let num = format!("{}{}", get_random_element(IMEI_TACS.iter()), randint(100000, 999999));
format!("{num}{}", luhn::checksum(num.as_bytes()))
}
pub fn pin() -> String {
custom_code("####", '@', '#')
}
}