validate_customer_code/
validate_customer_code.rs

1//! Validate customer code generation
2//!
3use tmflib::{tmf629::customer::Customer, HasId, HasName};
4
5fn main() -> Result<(), String> {
6    let mut cust1 = Customer::default();
7
8    cust1.set_name("NATIONAL BEVERAGE COMPANY LIMITED");
9    cust1.id = Some(String::from("123456"));
10    cust1.generate_code(None);
11
12    let code1 = cust1
13        .get_characteristic("code")
14        .ok_or(String::from("No Value"))?;
15    let hash = cust1
16        .get_characteristic("hash")
17        .ok_or(String::from("No Value"))?;
18
19    println!(
20        "Customer: {} + ID: {} Offset=0\t generates Code: {}",
21        cust1.get_name(),
22        cust1.get_id(),
23        code1.value
24    );
25    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
26
27    cust1.generate_code(Some(1));
28
29    let code1 = cust1
30        .get_characteristic("code")
31        .ok_or(String::from("No Value"))?;
32    let hash = cust1
33        .get_characteristic("hash")
34        .ok_or(String::from("No Value"))?;
35
36    println!(
37        "Customer: {} + ID: {} Offset=1\t generates Code: {}",
38        cust1.get_name(),
39        cust1.get_id(),
40        code1.value
41    );
42    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
43
44    Ok(())
45}