Skip to main content

Sedol

Struct Sedol 

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

A validated Stock Exchange Daily Official List number (SEDOL).

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

§Examples

use regit_identifiers::Sedol;

let sedol = Sedol::parse("0263494").unwrap();
assert_eq!(sedol.body(), "026349");
assert_eq!(sedol.check_digit(), '4');
assert_eq!(sedol.as_str(), "0263494");

Implementations§

Source§

impl Sedol

Source

pub const LENGTH: usize = 7

The number of characters in a SEDOL.

Source

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

Parses and fully validates a SEDOL.

Validation is strict and, in order: the input must be exactly 7 characters; characters 1–6 must each be an ASCII digit or an upper-case consonant (a vowel is rejected); character 7 must be an ASCII digit; and the check digit must equal the value recomputed from the six-character body.

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

assert!(Sedol::parse("0263494").is_ok());

// A single wrong digit is caught, not silently accepted.
assert_eq!(
    Sedol::parse("0263495"),
    Err(ValidationError::BadCheckDigit { expected: '4', found: '5' }),
);
Source

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

Validates a SEDOL without constructing one.

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

§Errors

Returns the same ValidationError variants as Sedol::parse.

§Examples
use regit_identifiers::Sedol;

assert!(Sedol::validate("0263494").is_ok());
assert!(Sedol::validate("0263495").is_err());
Source

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

Wraps 7 raw bytes as a Sedol without any validation.

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

§Examples
use regit_identifiers::Sedol;

let sedol = Sedol::from_bytes_unchecked(*b"0263494");
assert_eq!(sedol.as_str(), "0263494");
Source

pub fn as_str(&self) -> &str

Returns the SEDOL as a string slice.

§Examples
use regit_identifiers::Sedol;

assert_eq!(Sedol::parse("0263494").unwrap().as_str(), "0263494");
Source

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

Returns the SEDOL as its 7 raw ASCII bytes.

§Examples
use regit_identifiers::Sedol;

assert_eq!(Sedol::parse("0263494").unwrap().as_bytes(), b"0263494");
Source

pub fn body(&self) -> &str

Returns the six-character body, characters 1–6.

§Examples
use regit_identifiers::Sedol;

assert_eq!(Sedol::parse("0263494").unwrap().body(), "026349");
Source

pub fn check_digit(&self) -> char

Returns the check digit, character 7.

§Examples
use regit_identifiers::Sedol;

assert_eq!(Sedol::parse("0263494").unwrap().check_digit(), '4');
Source

pub fn is_legacy_numeric(&self) -> bool

Returns true if this is a legacy purely-numeric SEDOL.

SEDOLs issued before the 2004 switch to an alphanumeric scheme have a body consisting solely of digits; this is true exactly when all six body characters are ASCII digits.

§Examples
use regit_identifiers::Sedol;

assert!(Sedol::parse("0263494").unwrap().is_legacy_numeric());
assert!(!Sedol::parse("B0WNLY7").unwrap().is_legacy_numeric());

Trait Implementations§

Source§

impl AsRef<str> for Sedol

Source§

fn as_ref(&self) -> &str

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

impl Clone for Sedol

Source§

fn clone(&self) -> Sedol

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 Sedol

Source§

impl Debug for Sedol

Source§

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

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

impl Display for Sedol

Source§

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

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

impl Eq for Sedol

Source§

impl FromStr for Sedol

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 Sedol

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 Sedol

Source§

fn eq(&self, other: &Sedol) -> 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 Sedol

Auto Trait Implementations§

§

impl Freeze for Sedol

§

impl RefUnwindSafe for Sedol

§

impl Send for Sedol

§

impl Sync for Sedol

§

impl Unpin for Sedol

§

impl UnsafeUnpin for Sedol

§

impl UnwindSafe for Sedol

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.