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
| Constructor | Accepts |
|---|---|
Isin::parse / Isin::new | 12-character strings, any ASCII case, trimmed |
Isin::from_bytes | Exactly 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
impl Isin
Sourcepub fn parse(input: &str) -> Result<Self, IsinError>
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 digitSourcepub fn new(input: &str) -> Result<Self, IsinError>
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"));Sourcepub fn from_bytes(bytes: [u8; 12]) -> Result<Self, IsinError>
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());Sourcepub fn as_bytes(&self) -> &[u8; 12]
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");Sourcepub fn as_str(&self) -> &str
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");Sourcepub fn country_code(&self) -> &str
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");Sourcepub fn country(&self) -> Option<CountryCode>
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()));Sourcepub fn nsin(&self) -> &str
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");Sourcepub fn check_digit(&self) -> u8
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);Sourcepub fn computed_check_digit(&self) -> u8
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
impl<'a> Arbitrary<'a> for Isin
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreimpl Copy for Isin
Source§impl<'de> Deserialize<'de> for Isin
impl<'de> Deserialize<'de> for Isin
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Isin
Source§impl JsonSchema for Isin
impl JsonSchema for Isin
Source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Isin
impl Ord for Isin
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Isin
impl PartialOrd for Isin
impl StructuralPartialEq for Isin
Source§impl TryFrom<&[u8]> for Isin
impl TryFrom<&[u8]> for Isin
Source§fn try_from(value: &[u8]) -> Result<Self, Self::Error>
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.