Skip to main content

BasisPoints

Struct BasisPoints 

Source
pub struct BasisPoints(/* private fields */);
Expand description

A validated basis-points value in the inclusive range 0..=10_000.

Implementations§

Source§

impl BasisPoints

Source

pub const MAX: u16 = 10000

The maximum valid basis-points value (10000, equal to 100%).

Source

pub fn new(bps: u16) -> Result<Self, BasisPointsError>

Creates a new BasisPoints after validating the input range.

Returns BasisPointsError::InvalidBasisPoints if bps > 10_000.

Source

pub fn checked_add(self, rhs: Self) -> Option<Self>

Checked addition. Returns None if the result exceeds 10_000.

Source

pub fn checked_sub(self, rhs: Self) -> Option<Self>

Checked subtraction. Returns None if underflow occurs.

Source

pub fn checked_mul(self, rhs: Self) -> Option<Self>

Checked multiplication. Returns None if the result exceeds 10_000.

Source

pub fn checked_div(self, rhs: Self) -> Option<Self>

Checked division. Returns None on division-by-zero.

Trait Implementations§

Source§

impl BorshDeserialize for BasisPoints

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for BasisPoints

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for BasisPoints

Source§

fn clone(&self) -> BasisPoints

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 BasisPoints

Source§

impl Debug for BasisPoints

Source§

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

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

impl Eq for BasisPoints

Source§

impl From<BasisPoints> for Decimal

Available on crate feature decimal only.
Source§

fn from(bps: BasisPoints) -> Self

Converts basis points to a proportional rate in 0..=1 (divide by 10_000).

Source§

impl From<BasisPoints> for u128

Source§

fn from(bps: BasisPoints) -> Self

Converts to this type from the input type.
Source§

impl From<BasisPoints> for u16

Source§

fn from(bps: BasisPoints) -> Self

Converts to this type from the input type.
Source§

impl From<BasisPoints> for u32

Source§

fn from(bps: BasisPoints) -> Self

Converts to this type from the input type.
Source§

impl From<BasisPoints> for u64

Source§

fn from(bps: BasisPoints) -> Self

Converts to this type from the input type.
Source§

impl IdlBuild for BasisPoints

Source§

fn create_type() -> Option<IdlTypeDef>

Create an IDL type definition for the type. Read more
Source§

fn insert_types(types: &mut BTreeMap<String, IdlTypeDef>)

Insert all types that are included in the current type definition to the given map.
Source§

fn get_full_path() -> String

Get the full module path of the type. Read more
Source§

impl PartialEq for BasisPoints

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Pod for BasisPoints

Source§

impl Space for BasisPoints

Source§

impl StructuralPartialEq for BasisPoints

Source§

impl TryFrom<Decimal> for BasisPoints

Available on crate feature decimal only.
Source§

fn try_from(decimal: Decimal) -> Result<Self, Self::Error>

Converts a proportional rate in 0..=1 to basis points (multiply by 10_000).

Fractional results truncate toward zero when casting to u16.

Source§

type Error = BasisPointsError

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

impl Zeroable for BasisPoints

Source§

fn zeroed() -> Self

Auto Trait Implementations§

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> AnyBitPattern for T
where T: Pod,

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> NoUninit for T
where T: Pod,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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, 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<'a, T, U> TryFromFilter<'a, U> for T
where T: 'a, &'a T: TryFrom<U>,

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.