Skip to main content

country_code_valid

Function country_code_valid 

Source
pub fn country_code_valid(code: &str) -> bool
Expand description

ISO 3166-1 alpha-2: two uppercase ASCII letters that are an officially assigned country code. Shape-only candidates such as XX/QZ/AA are rejected because they are not in the assigned set.

Examples found in repository?
examples/regulatory_rules.rs (line 102)
14fn main() {
15    println!("=== Textile: fibre composition (must sum to ~100%) ===\n");
16
17    let good = [
18        FibreInput {
19            fibre: "cotton",
20            pct: 70.0,
21            country_of_origin: Some("IN"),
22        },
23        FibreInput {
24            fibre: "recycled_polyester",
25            pct: 30.0,
26            country_of_origin: Some("DE"),
27        },
28    ];
29    println!("  sum_ok(70 + 30) = {}", fibre_sum_ok(&[70.0, 30.0]));
30    println!(
31        "  validate(good)  = {:?}",
32        validate_fibre_composition(&good)
33    );
34
35    let bad = [FibreInput {
36        fibre: "cotton",
37        pct: 80.0,
38        country_of_origin: None,
39    }];
40    println!(
41        "  validate(80% only) = {:?}",
42        validate_fibre_composition(&bad)
43    );
44
45    println!("\n=== Chemicals: SVHC declarations (REACH Art. 33, 0.1% w/w) ===\n");
46
47    let svhcs = [
48        SvhcInput {
49            cas_number: "80-05-7",
50            substance_name: "Bisphenol A",
51            concentration_pct: 0.15,
52        },
53        SvhcInput {
54            cas_number: "117-81-7",
55            substance_name: "DEHP",
56            concentration_pct: 0.05,
57        },
58    ];
59    println!(
60        "  structural validation = {:?}",
61        validate_svhc_substances(&svhcs)
62    );
63    for finding in check_svhc_declarations(&svhcs) {
64        println!(
65            "  finding[{}]: {} ({}) at {:.2}% -> {:?}",
66            finding.index,
67            finding.substance_name,
68            finding.cas_number,
69            finding.concentration_pct,
70            finding.kind
71        );
72    }
73
74    println!("\n=== Battery: Art. 8(2) recycled-content targets (from 2031) ===\n");
75
76    let recycled = RecycledContentInput {
77        cobalt_pct: Some(10.0), // below the 16% Phase-1 target
78        lithium_pct: Some(6.0),
79        nickel_pct: Some(6.0),
80        lead_pct: Some(85.0),
81    };
82    let shortfalls = art8_shortfalls_2031(&recycled);
83    if shortfalls.is_empty() {
84        println!("  all declared metals meet Phase-1 targets");
85    } else {
86        for s in shortfalls {
87            println!(
88                "  shortfall: {} declared {:.1}% < required {:.1}%",
89                s.material, s.declared_pct, s.required_pct
90            );
91        }
92    }
93    println!(
94        "  mercury 0.0010% prohibited? {}",
95        mercury_content_prohibited(0.0010)
96    );
97
98    println!("\n=== Common: ISO 3166-1 alpha-2 country codes ===\n");
99    for code in ["DE", "in", "XX", "USA"] {
100        println!(
101            "  country_code_valid({code:>3}) = {}",
102            country_code_valid(code)
103        );
104    }
105}