SafeMath

Trait SafeMath 

Source
pub trait SafeMath {
    type Output;

    // Required methods
    fn safe_add(
        &self,
        rhs: Self::Output,
    ) -> StdResult<Self::Output, ProgramError>;
    fn safe_sub(
        &self,
        rhs: Self::Output,
    ) -> StdResult<Self::Output, ProgramError>;
    fn safe_div(
        &self,
        rhs: Self::Output,
    ) -> StdResult<Self::Output, ProgramError>;
    fn safe_mul(
        &self,
        rhs: Self::Output,
    ) -> StdResult<Self::Output, ProgramError>;
    fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>;
}
Expand description

Defines a set of safe math operations that return a ProgramError which is expected in an anchor instruction execution.

Required Associated Types§

Required Methods§

Source

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Implementations on Foreign Types§

Source§

impl SafeMath for u8

$type implementation of the SafeMath trait

Source§

type Output = u8

Source§

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Source§

impl SafeMath for u16

$type implementation of the SafeMath trait

Source§

type Output = u16

Source§

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Source§

impl SafeMath for u32

$type implementation of the SafeMath trait

Source§

type Output = u32

Source§

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Source§

impl SafeMath for u64

$type implementation of the SafeMath trait

Source§

type Output = u64

Source§

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Source§

impl SafeMath for u128

$type implementation of the SafeMath trait

Source§

type Output = u128

Source§

fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>

Source§

fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>

Implementors§