Skip to main content

Isin

Struct Isin 

Source
pub struct Isin { /* private fields */ }
Expand description

A validated ISIN (International Securities Identification Number, ISO 6166).

Isin is a 12-byte, Copy, allocation-free value object. Once constructed, it is guaranteed to satisfy the structural rules and Luhn check digit required by ISO 6166 — there is no way to obtain an Isin that hasn’t passed validation.

Internally, the identifier is stored as raw uppercase ASCII bytes ('0'..='9' or 'A'..='Z').

§Constructing an Isin

ConstructorAccepts
Isin::parse / Isin::new12-character strings, any ASCII case, trimmed
Isin::from_bytesExactly 12 pre-normalized uppercase ASCII bytes
FromStr / TryFrom<&str>Same as parse, for use in generic code

All of them run the same validation and return IsinError on failure. See the module-level documentation for the segment layout and design rationale.

Implementations§

Source§

impl Isin

Source

pub fn parse(input: &str) -> Result<Self, IsinError>

Parses an ISIN from a string.

The parser trims surrounding whitespace and folds ASCII letters to uppercase before validation. This is the primary constructor; Isin::new, FromStr, and TryFrom<&str> all delegate to it.

§Errors

Returns IsinError if the input is empty, does not contain exactly 12 characters after trimming, contains a character invalid for its position, or fails the Luhn check digit.

§Examples
use ftracker_identifiers::Isin;

assert!(Isin::parse("US0378331005").is_ok());
assert!(Isin::parse("us0378331005").is_ok()); // lowercase is folded automatically
assert!(Isin::parse(" US0378331005 ").is_ok()); // surrounding whitespace is trimmed
assert!(Isin::parse("US0378331006").is_err()); // wrong check digit
Source

pub fn new(input: &str) -> Result<Self, IsinError>

Alias for Isin::parse.

§Errors

See Isin::parse.

§Examples
use ftracker_identifiers::Isin;

assert_eq!(Isin::new("US0378331005"), Isin::parse("US0378331005"));
Source

pub fn from_bytes(bytes: [u8; 12]) -> Result<Self, IsinError>

Constructs an Isin directly from 12 raw ASCII bytes.

Each byte must already be uppercase and valid for its position (two letters, nine alphanumerics, one digit). Use Isin::parse if the input might contain surrounding whitespace or lowercase letters.

§Errors

Returns IsinError under the same conditions as Isin::parse, except that length is guaranteed by the [u8; 12] type itself: IsinError::InvalidLength cannot occur here.

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::from_bytes(*b"US0378331005").unwrap();
assert_eq!(isin.as_str(), "US0378331005");

// A malformed checksum is rejected just like it would be through `parse`.
assert!(Isin::from_bytes(*b"US0378331006").is_err());
Source

pub fn as_bytes(&self) -> &[u8; 12]

Returns the 12 raw ASCII bytes backing this ISIN (for example, b"US0378331005").

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.as_bytes(), b"US0378331005");
Source

pub fn as_str(&self) -> &str

Returns the full 12-character ISIN as a &str.

This never allocates: the bytes are guaranteed to be valid ASCII by construction.

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.as_str(), "US0378331005");
Source

pub fn country_code(&self) -> &str

Returns the two-character ISO 3166-1 alpha-2 country code (positions 1–2).

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.country_code(), "US");
Source

pub fn country(&self) -> Option<CountryCode>

Returns the prefix (positions 1-2) as a validated CountryCode, or None when it is not an officially assigned ISO 3166-1 alpha-2 code.

An Isin only validates its prefix structurally (two uppercase letters), so it can carry prefixes that ISO 6166 reserves but ISO 3166-1 does not assign. The most common are XS (used by international clearing systems such as Euroclear and Clearstream), EU (European Union supranational issues), and QS. For those, this returns None even though the Isin itself is valid. Use Isin::country_code when you want the raw two letter prefix regardless of assignment.

§Examples
use ftracker_identifiers::{Isin, CountryCode};

let apple = Isin::parse("US0378331005").unwrap();
assert_eq!(apple.country(), Some(CountryCode::parse("US").unwrap()));
Source

pub fn nsin(&self) -> &str

Returns the nine-character National Securities Identifying Number (positions 3–11).

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.nsin(), "037833100");
Source

pub fn check_digit(&self) -> u8

Returns the Luhn check digit (position 12) as a numeric value.

For a valid Isin, this always equals Isin::computed_check_digit.

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.check_digit(), 5);
Source

pub fn computed_check_digit(&self) -> u8

Recomputes the check digit that the ISO 6166 Luhn algorithm produces from the first 11 characters of this value.

For a valid Isin this always matches Isin::check_digit; the method exists so callers can reproduce the algorithm’s output without a separate crate.

§Examples
use ftracker_identifiers::Isin;

let isin = Isin::parse("US0378331005").unwrap();
assert_eq!(isin.computed_check_digit(), isin.check_digit());

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for Isin

Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl AsRef<[u8]> for Isin

Source§

fn as_ref(&self) -> &[u8]

Equivalent to Isin::as_bytes, borrowed as a slice.

Source§

impl AsRef<str> for Isin

Source§

fn as_ref(&self) -> &str

Equivalent to Isin::as_str.

Source§

impl Clone for Isin

Source§

fn clone(&self) -> Isin

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Isin

Source§

impl Debug for Isin

Source§

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

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

impl<'de> Deserialize<'de> for Isin

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Isin

Source§

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

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

impl Eq for Isin

Source§

impl FromStr for Isin

Source§

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

Delegates to Isin::parse, enabling input.parse::<Isin>() and use in generic code bounded by FromStr.

Source§

type Err = IsinError

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

impl Hash for Isin

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JsonSchema for Isin

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

impl Ord for Isin

Source§

fn cmp(&self, other: &Isin) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Isin

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for Isin

Source§

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

Compares against a string slice by its canonical 12 character representation.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Isin> for str

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Isin> for &str

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Isin

Source§

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

Compares against a string slice by its canonical 12 character representation.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Isin

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Serialize for Isin

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Isin

Source§

impl TryFrom<&[u8]> for Isin

Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Validates a byte slice as an ISIN. The slice must be exactly 12 pre normalized uppercase ASCII bytes; any other length yields IsinError::InvalidLength. Once the length is confirmed, this behaves like Isin::from_bytes.

Source§

type Error = IsinError

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

impl TryFrom<&str> for Isin

Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Delegates to Isin::parse, enabling Isin::try_from(input) and use in generic code bounded by TryFrom<&str>.

Source§

type Error = IsinError

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

impl TryFrom<[u8; 12]> for Isin

Source§

fn try_from(value: [u8; 12]) -> Result<Self, Self::Error>

Delegates to Isin::from_bytes. The bytes must already be pre normalized uppercase ASCII.

Source§

type Error = IsinError

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl Freeze for Isin

§

impl RefUnwindSafe for Isin

§

impl Send for Isin

§

impl Sync for Isin

§

impl Unpin for Isin

§

impl UnsafeUnpin for Isin

§

impl UnwindSafe for Isin

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V