pub struct HsCode(/* private fields */);Expand description
A validated HS Code stored as a vector of numeric bytes (0-9).
The inner Vec<u8> stores each digit as its numeric value for efficient
comparison and slicing. Use the provided constructors to create a valid HsCode.
§Example
let code = HsCode::new_from_str("010121");
assert_eq!(code.get_chapter(), 1);Implementations§
Source§impl HsCode
impl HsCode
Sourcepub fn new_from_str(input: &str) -> Self
pub fn new_from_str(input: &str) -> Self
Creates an `HsCode` from a string, panicking on invalid input.
Use this only when the input is guaranteed to be valid.
For fallible parsing, use `try_new_from_str` or `FromStr::from_str`.Sourcepub fn get_chapter(&self) -> u8
pub fn get_chapter(&self) -> u8
Returns the chapter number (first two digits) as a u8.
§Example
let code = HsCode::new_from_str("01012100");
assert_eq!(code.get_chapter(), 1);Sourcepub fn try_new_from_str(input: &str) -> Result<Self, HscodeError>
pub fn try_new_from_str(input: &str) -> Result<Self, HscodeError>
Attempts to parse an HsCode from a string.
This is the main fallible constructor. It validates length, digit characters, and chapter range.
Sourcepub fn diff(&self, other: &HsCode) -> Vec<usize>
pub fn diff(&self, other: &HsCode) -> Vec<usize>
Returns the 0‑based indices where two HS Codes differ.
Only valid positions in the shorter code are considered.
§Example
let a = HsCode::new_from_str("010121");
let b = HsCode::new_from_str("010128");
assert_eq!(a.diff(&b), vec![5]);Sourcepub fn description(&self) -> Option<&'static str>
pub fn description(&self) -> Option<&'static str>
Looks up the commodity description for the first 6 digits.
The description comes from a precompiled static map generated from
data/harmonized-system.csv at build time.
Returns None if the 6‑digit prefix is not found.
Sourcepub fn is_six_digit(&self) -> bool
pub fn is_six_digit(&self) -> bool
Returns true if this HS code has the standard 6-digit international length.
Sourcepub fn is_ten_digit(&self) -> bool
pub fn is_ten_digit(&self) -> bool
Returns true if this HS code has the full 10-digit China-specific length.
Trait Implementations§
Source§impl FromStr for HsCode
Enables parsing an HsCode from a string using the parse() method.
impl FromStr for HsCode
Enables parsing an HsCode from a string using the parse() method.
§Example
use gukasha_rustrade::HsCode;
use std::str::FromStr;
let code = HsCode::from_str("01012100").unwrap();