Trait Option Checked Add
pub trait OptionCheckedAdd<Rhs = Self, InnerRhs = Rhs> {
type Output;
// Required method
fn opt_checked_add(self, rhs: Rhs) -> Result<Option<Self::Output>, Error>;
}Expand description
Trait for values and Options checked addition.
Implementing this trait leads to the following auto-implementations:
OptionCheckedAdd<Option<InnerRhs>>forT.OptionCheckedAdd<Rhs>forOption<T>.OptionCheckedAdd<Option<InnerRhs>>forOption<T>.- … and some variants with references.
Note that since the std library doesn’t define any
CheckedAdd trait,
users must provide the base implementation for the inner type.
Required Associated Types§
type Output
type Output
The resulting inner type after applying the addition.
Required Methods§
fn opt_checked_add(self, rhs: Rhs) -> Result<Option<Self::Output>, Error>
fn opt_checked_add(self, rhs: Rhs) -> Result<Option<Self::Output>, Error>
Computes the checked addition.
- Returns
Ok(Some(result))ifresultcould be computed. - Returns
Ok(None)if at least one argument isNone. - Returns
Err(Error::Overflow)if an overflow occured.