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§
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>
Implementations on Foreign Types§
Source§impl SafeMath for u8
$type implementation of the SafeMath trait
impl SafeMath for u8
$type implementation of the SafeMath trait
type Output = u8
fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>
Source§impl SafeMath for u16
$type implementation of the SafeMath trait
impl SafeMath for u16
$type implementation of the SafeMath trait
type Output = u16
fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>
Source§impl SafeMath for u32
$type implementation of the SafeMath trait
impl SafeMath for u32
$type implementation of the SafeMath trait
type Output = u32
fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>
Source§impl SafeMath for u64
$type implementation of the SafeMath trait
impl SafeMath for u64
$type implementation of the SafeMath trait
type Output = u64
fn safe_add(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_sub(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_mul(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_div(&self, rhs: Self::Output) -> StdResult<Self::Output, ProgramError>
fn safe_pow(&self, exp: u32) -> StdResult<Self::Output, ProgramError>
Source§impl SafeMath for u128
$type implementation of the SafeMath trait
impl SafeMath for u128
$type implementation of the SafeMath trait