pub struct CUSIP(/* private fields */);
Expand description
A CUSIP in confirmed valid format.
You cannot construct a CUSIP value manually. This does not compile:
use cusip;
let cannot_construct = cusip::CUSIP([0_u8; 9]);
Implementations§
source§impl CUSIP
impl CUSIP
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, CUSIPError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CUSIPError>
Constructs a CUSIP
from a byte array of length 9.
The byte array must contain only ASCII alphanumeric characters. The first 8 characters represent the issuer and issue numbers, and the 9th character is the check digit.
§Errors
Returns CUSIPError
if the byte array is not a valid CUSIP.
§Examples
use cusip::{CUSIP, CUSIPError};
let bytes = *b"037833100";
let cusip = CUSIP::from_bytes(&bytes).unwrap();
assert_eq!(cusip.to_string(), "037833100");
let invalid_bytes = *b"invalid!!";
assert!(CUSIP::from_bytes(&invalid_bytes).is_err());
sourcepub fn parse(value: &str) -> Result<CUSIP, CUSIPError>
pub fn parse(value: &str) -> Result<CUSIP, CUSIPError>
Parse a string to a valid CUSIP or an error, requiring the string to already be only uppercase alphanumerics with no leading or trailing whitespace in addition to being the right length and format.
sourcepub fn parse_loose(value: &str) -> Result<CUSIP, CUSIPError>
pub fn parse_loose(value: &str) -> Result<CUSIP, CUSIPError>
Parse a string to a valid CUSIP or an error message, allowing the string to contain leading or trailing whitespace and/or lowercase letters as long as it is otherwise the right length and format.
sourcepub fn as_cins(&self) -> Option<CINS<'_>>
pub fn as_cins(&self) -> Option<CINS<'_>>
Returns a reference to the CINS
representation of this CUSIP
,
if it is a valid CINS identifier.
§Examples
use cusip::{CUSIP, CINS};
let cusip = CUSIP::parse("S08000AA9").unwrap();
if let Some(cins) = cusip.as_cins() {
assert_eq!(cins.country_code(), 'S');
assert_eq!(cins.issuer_num(), "08000");
} else {
println!("Not a CINS");
}
let non_cins_cusip = CUSIP::parse("037833100").unwrap();
assert!(non_cins_cusip.as_cins().is_none());
sourcepub fn is_cins(&self) -> bool
pub fn is_cins(&self) -> bool
Returns true if this CUSIP number is actually a CUSIP International Numbering System
(CINS) number, false otherwise (i.e., that it has a letter as the first character of its
issuer number). See also is_cins_base()
and is_cins_extended()
.
sourcepub fn is_cins_base(&self) -> bool
👎Deprecated: Use CUSIP::as_cins and CINS::is_cins_base.
pub fn is_cins_base(&self) -> bool
Returns true if this CUSIP identifier is actually a CUSIP International Numbering System
(CINS) identifier (with the further restriction that it does not use ‘I’, ‘O’ or ‘Z’ as
its country code), false otherwise. See also is_cins()
and is_cins_extended()
.
sourcepub fn is_cins_extended(&self) -> bool
👎Deprecated: Use CUSIP::as_cins and CINS::is_cins_extended.
pub fn is_cins_extended(&self) -> bool
Returns true if this CUSIP identifier is actually a CUSIP International Numbering System (CINS) identifier (with the further restriction that it does use ‘I’, ‘O’ or ‘Z’ as its country code), false otherwise.
sourcepub fn cins_country_code(&self) -> Option<char>
👎Deprecated: Use CUSIP::as_cins and CINS::country_code.
pub fn cins_country_code(&self) -> Option<char>
Returns Some(c) containing the first character of the CUSIP if it is actually a CUSIP International Numbering System (CINS) identifier, None otherwise.
sourcepub fn issuer_num(&self) -> &str
pub fn issuer_num(&self) -> &str
Return just the Issuer Number portion of the CUSIP.
sourcepub fn has_private_issuer(&self) -> bool
pub fn has_private_issuer(&self) -> bool
Returns true if the Issuer Number is reserved for private use.
sourcepub fn is_private_issue(&self) -> bool
pub fn is_private_issue(&self) -> bool
Returns true if the Issue Number is reserved for private use.
sourcepub fn is_private_use(&self) -> bool
pub fn is_private_use(&self) -> bool
Returns true if the CUSIP is reserved for private use (i.e., either it has a private issuer or it is a private issue).
sourcepub fn check_digit(&self) -> char
pub fn check_digit(&self) -> char
Return just the Check Digit portion of the CUSIP.
Trait Implementations§
source§impl Ord for CUSIP
impl Ord for CUSIP
source§impl PartialEq for CUSIP
impl PartialEq for CUSIP
source§impl PartialOrd for CUSIP
impl PartialOrd for CUSIP
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more