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
impl Sedol
Sourcepub fn parse(s: &str) -> Result<Self, ValidationError>
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
ValidationError::WrongLengthif the input is not 7 characters.ValidationError::InvalidCharacterif a character falls outside the set its position allows — this rejects a vowel in the body, a non-digit check character, lower-case input, and any non-ASCII character.ValidationError::BadCheckDigitif the supplied check digit does not match the recomputed one.
§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' }),
);Sourcepub fn validate(s: &str) -> Result<(), ValidationError>
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());Sourcepub const fn from_bytes_unchecked(bytes: [u8; 7]) -> Self
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");Sourcepub fn as_str(&self) -> &str
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");Sourcepub fn as_bytes(&self) -> &[u8]
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");Sourcepub fn body(&self) -> &str
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");Sourcepub fn check_digit(&self) -> char
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');Sourcepub fn is_legacy_numeric(&self) -> bool
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());