Skip to main content

HsCode

Struct HsCode 

Source
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

Source

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`.
Source

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);
Source

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.

Source

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]);
Source

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.

Source

pub fn len(&self) -> usize

Returns the total number of digits in this HS code.

Source

pub fn is_empty(&self) -> bool

HS codes are never empty. This method always returns false.

Source

pub fn is_six_digit(&self) -> bool

Returns true if this HS code has the standard 6-digit international length.

Source

pub fn is_ten_digit(&self) -> bool

Returns true if this HS code has the full 10-digit China-specific length.

Source

pub fn iter(&self) -> Iter<'_, u8>

Returns an iterator over the digits as u8 values.

Source

pub fn chars(&self) -> impl Iterator<Item = char> + '_

Returns an iterator over the digits as chars (e.g., ‘0’..‘9’).

Trait Implementations§

Source§

impl Debug for HsCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for HsCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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();
Source§

type Err = HscodeError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for HsCode

Source§

fn eq(&self, other: &HsCode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for HsCode

Source§

fn partial_cmp(&self, other: &HsCode) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for HsCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.