Skip to main content

hs_predict/rules/
types.rs

1//! Types for the static HS rule table.
2
3use std::ops::RangeInclusive;
4
5/// Physical shape pattern used as a condition in an [`HsRule`].
6#[derive(Debug)]
7pub enum ShapePattern {
8    /// Matches any physical form.
9    Any,
10    /// Solid (bulk, pellets, flakes, rods, etc.).
11    Solid,
12    /// Powder (fine-grained).
13    Powder,
14    /// Granules (coarser than powder).
15    Granules,
16    /// Pure liquid (not a solution).
17    Liquid,
18    /// Solution, optionally constrained to a concentration range (w/w%).
19    Solution {
20        /// `None` = no concentration constraint.
21        concentration_range_pct: Option<RangeInclusive<f64>>,
22    },
23    /// Gas or vapour.
24    Gas,
25    /// Metal foil.
26    Foil,
27    /// Cast metal (ingot, billet, slab, etc.).
28    Ingot,
29}
30
31/// A single HS classification rule for a known CAS number.
32///
33/// Rules are stored in a `&'static [HsRule]` slice embedded at compile time,
34/// so zero heap allocation is needed at runtime.
35#[derive(Debug)]
36pub struct HsRule {
37    /// CAS registry number (e.g. `"1310-73-2"`).
38    pub cas: &'static str,
39
40    /// Required physical form for this rule to match.
41    pub shape: ShapePattern,
42
43    /// Optional purity constraint (w/w%). `None` = no constraint.
44    pub purity_range: Option<RangeInclusive<f64>>,
45
46    /// Six-digit HS 2022 code (no dots, e.g. `"281511"`).
47    pub hs_code: &'static str,
48
49    /// Human-readable description of the HS heading.
50    pub heading_description: &'static str,
51
52    /// Confidence score (0.0–1.0) for this rule.
53    pub confidence: f32,
54}