Skip to main content

Lei

Struct Lei 

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

A validated Legal Entity Identifier (ISO 17442).

A Lei can only be created by Lei::parse (or the explicitly unchecked Lei::from_bytes_unchecked), so a value of this type is a proof that the 20 characters form a structurally valid LEI with correct check digits. It stores the identifier inline as [u8; 20], is Copy, and allocates nothing.

§Examples

use regit_identifiers::Lei;

let lei = Lei::parse("5493001KJTIIGC8Y1R12").unwrap();
assert_eq!(lei.lou_prefix(), "5493");
assert_eq!(lei.entity_id(), "1KJTIIGC8Y1R");
assert_eq!(lei.check_digits(), "12");
assert_eq!(lei.as_str(), "5493001KJTIIGC8Y1R12");

Implementations§

Source§

impl Lei

Source

pub const LENGTH: usize = 20

The number of characters in an LEI.

Source

pub fn parse(s: &str) -> Result<Self, ValidationError>

Parses and fully validates an LEI.

Validation is strict and, in order: the input must be exactly 20 characters; characters 1–18 must each be an ASCII digit or upper-case letter and characters 19–20 ASCII digits; characters 5–6 must be the reserved literal 00; and the two check digits must equal the values recomputed from the 18-character body.

§Errors
§Examples
use regit_identifiers::Lei;
use regit_identifiers::errors::ValidationError;

assert!(Lei::parse("5493001KJTIIGC8Y1R12").is_ok());

// A single wrong check digit is caught, not silently accepted.
assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R13"),
    Err(ValidationError::BadCheckDigit { expected: '2', found: '3' }),
);
Source

pub fn validate(s: &str) -> Result<(), ValidationError>

Validates an LEI without constructing one.

Equivalent to Lei::parse(s).map(|_| ()); use it when only the verdict is needed.

§Errors

Returns the same ValidationError variants as Lei::parse.

§Examples
use regit_identifiers::Lei;

assert!(Lei::validate("5493001KJTIIGC8Y1R12").is_ok());
assert!(Lei::validate("5493001KJTIIGC8Y1R13").is_err());
Source

pub const fn from_bytes_unchecked(bytes: [u8; 20]) -> Self

Wraps 20 raw bytes as a Lei without any validation.

The caller asserts that bytes holds the 20 ASCII characters of a valid LEI. This exists for reconstructing a Lei from bytes that were validated earlier; prefer Lei::parse for any untrusted input.

§Examples
use regit_identifiers::Lei;

let lei = Lei::from_bytes_unchecked(*b"5493001KJTIIGC8Y1R12");
assert_eq!(lei.as_str(), "5493001KJTIIGC8Y1R12");
Source

pub fn as_str(&self) -> &str

Returns the LEI as a string slice.

§Examples
use regit_identifiers::Lei;

assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R12").unwrap().as_str(),
    "5493001KJTIIGC8Y1R12",
);
Source

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

Returns the LEI as its 20 raw ASCII bytes.

§Examples
use regit_identifiers::Lei;

assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R12").unwrap().as_bytes(),
    b"5493001KJTIIGC8Y1R12",
);
Source

pub fn lou_prefix(&self) -> &str

Returns the four-character LOU prefix, characters 1–4.

§Examples
use regit_identifiers::Lei;

assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R12").unwrap().lou_prefix(),
    "5493",
);
Source

pub fn entity_id(&self) -> &str

Returns the twelve-character entity ID, characters 7–18 (the segment ISO 17442 calls the entity-specific part).

§Examples
use regit_identifiers::Lei;

assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R12").unwrap().entity_id(),
    "1KJTIIGC8Y1R",
);
Source

pub fn check_digits(&self) -> &str

Returns the two check digits, characters 19–20.

§Examples
use regit_identifiers::Lei;

assert_eq!(
    Lei::parse("5493001KJTIIGC8Y1R12").unwrap().check_digits(),
    "12",
);

Trait Implementations§

Source§

impl AsRef<str> for Lei

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Lei

Source§

fn clone(&self) -> Lei

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 Lei

Source§

impl Debug for Lei

Source§

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

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

impl Display for Lei

Source§

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

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

impl Eq for Lei

Source§

impl FromStr for Lei

Source§

type Err = ValidationError

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 Hash for Lei

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 PartialEq for Lei

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Lei

Auto Trait Implementations§

§

impl Freeze for Lei

§

impl RefUnwindSafe for Lei

§

impl Send for Lei

§

impl Sync for Lei

§

impl Unpin for Lei

§

impl UnsafeUnpin for Lei

§

impl UnwindSafe for Lei

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> 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> 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, 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.