Struct cusip::CUSIP

source ·
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

source

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());
source

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.

source

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.

source

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());
source

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().

source

pub fn is_cins_base(&self) -> bool

👎Deprecated: Use CUSIP::as_cins and CINS::is_cins_base.

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().

source

pub fn is_cins_extended(&self) -> bool

👎Deprecated: Use CUSIP::as_cins and CINS::is_cins_extended.

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.

source

pub fn cins_country_code(&self) -> Option<char>

👎Deprecated: Use CUSIP::as_cins and CINS::country_code.

Returns Some(c) containing the first character of the CUSIP if it is actually a CUSIP International Numbering System (CINS) identifier, None otherwise.

source

pub fn issuer_num(&self) -> &str

Return just the Issuer Number portion of the CUSIP.

source

pub fn has_private_issuer(&self) -> bool

Returns true if the Issuer Number is reserved for private use.

source

pub fn issue_num(&self) -> &str

Return just the Issue Number portion of the CUSIP.

source

pub fn is_private_issue(&self) -> bool

Returns true if the Issue Number is reserved for private use.

source

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

source

pub fn payload(&self) -> &str

Return the Payload — everything except the Check Digit.

source

pub fn check_digit(&self) -> char

Return just the Check Digit portion of the CUSIP.

Trait Implementations§

source§

impl Clone for CUSIP

source§

fn clone(&self) -> CUSIP

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CUSIP

source§

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

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

impl Display for CUSIP

source§

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

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

impl FromStr for CUSIP

§

type Err = CUSIPError

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 CUSIP

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 Ord for CUSIP

source§

fn cmp(&self, other: &CUSIP) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for CUSIP

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for CUSIP

source§

fn partial_cmp(&self, other: &CUSIP) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> TryFrom<&'a CUSIP> for CINS<'a>

§

type Error = &'static str

The type returned in the event of a conversion error.
source§

fn try_from(cusip: &'a CUSIP) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for CUSIP

source§

impl Eq for CUSIP

source§

impl StructuralPartialEq for CUSIP

Auto Trait Implementations§

§

impl RefUnwindSafe for CUSIP

§

impl Send for CUSIP

§

impl Sync for CUSIP

§

impl Unpin for CUSIP

§

impl UnwindSafe for CUSIP

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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.