Struct chain_path_derivation::SoftDerivation
source · pub struct SoftDerivation(Derivation);
Expand description
wrapper to guarantee the given derivation is a soft derivation
Tuple Fields§
§0: Derivation
Implementations§
source§impl SoftDerivation
impl SoftDerivation
sourcepub const fn new_unchecked(derivation: Derivation) -> Self
pub const fn new_unchecked(derivation: Derivation) -> Self
construct a soft derivation from the given derivation without checking the derivation is actually a soft derivation.
this function does not perform any verification and if the value is not correct it will create a cascade of issues, be careful when utilizing this function.
sourcepub fn new(derivation: Derivation) -> Result<Self, DerivationError>
pub fn new(derivation: Derivation) -> Result<Self, DerivationError>
build a soft derivation from the given Derivation
. If the value
is not a soft derivation it will return an error
Example
let derivation = Derivation::new(42);
let derivation = SoftDerivation::new(derivation)?;
println!("derivation: {}", derivation);
sourcepub const fn max_value() -> Self
pub const fn max_value() -> Self
returns the max derivation index value
let max = SoftDerivation::max_value();
assert_eq!(max, SoftDerivation::new_unchecked(Derivation::new(0x7FFF_FFFF)));
sourcepub const fn min_value() -> Self
pub const fn min_value() -> Self
returns the min derivation index value
let min = SoftDerivation::min_value();
assert_eq!(min, SoftDerivation::new_unchecked(Derivation::new(0)));
sourcepub fn overflowing_add(self, rhs: u32) -> (Self, bool)
pub fn overflowing_add(self, rhs: u32) -> (Self, bool)
calculate self + rhs
Returns the tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.
Examples
Basic usage:
assert_eq!(
SoftDerivation::new_unchecked(Derivation::new(5)).overflowing_add(2),
(SoftDerivation::new_unchecked(Derivation::new(7)), false)
);
assert_eq!(
SoftDerivation::max_value().overflowing_add(1),
(SoftDerivation::new_unchecked(Derivation::new(0)), true)
);
sourcepub fn saturating_add(self, rhs: u32) -> Self
pub fn saturating_add(self, rhs: u32) -> Self
saturating integer addition. Computes self + rhs
, saturating
at the numeric bounds instead of overflowing.
Examples
Basic usage:
assert_eq!(
SoftDerivation::new_unchecked(Derivation::new(100)).saturating_add(1),
SoftDerivation::new_unchecked(Derivation::new(101))
);
assert_eq!(
SoftDerivation::max_value().saturating_add(2048),
SoftDerivation::max_value(),
);
sourcepub fn checked_add(self, rhs: u32) -> Option<Self>
pub fn checked_add(self, rhs: u32) -> Option<Self>
checked integer addition. Computes self + rhs
, returning None
if overflow
would occurred.
Examples
Basic usage:
assert_eq!(
SoftDerivation::new_unchecked(Derivation::new(100)).checked_add(1),
Some(SoftDerivation::new_unchecked(Derivation::new(101)))
);
assert_eq!(
SoftDerivation::max_value().checked_add(2048),
None,
);
sourcepub fn wrapping_add(self, rhs: u32) -> Self
pub fn wrapping_add(self, rhs: u32) -> Self
Wrapping (modular) addition. Computes self + rhs
, wrapping around the boundary
of the type.
Examples
Basic usage:
assert_eq!(
SoftDerivation::new_unchecked(Derivation::new(100)).wrapping_add(1),
SoftDerivation::new_unchecked(Derivation::new(101))
);
assert_eq!(
SoftDerivation::max_value().wrapping_add(1),
SoftDerivation::new_unchecked(Derivation::new(0)),
);
fn saturating_sub(self, rhs: u32) -> Self
Methods from Deref<Target = u32>§
pub const MIN: u32 = 0u32
pub const MAX: u32 = 4_294_967_295u32
pub const BITS: u32 = 32u32
Trait Implementations§
source§impl Clone for SoftDerivation
impl Clone for SoftDerivation
source§fn clone(&self) -> SoftDerivation
fn clone(&self) -> SoftDerivation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SoftDerivation
impl Debug for SoftDerivation
source§impl Default for SoftDerivation
impl Default for SoftDerivation
source§impl Deref for SoftDerivation
impl Deref for SoftDerivation
source§impl Display for SoftDerivation
impl Display for SoftDerivation
source§impl From<SoftDerivation> for Derivation
impl From<SoftDerivation> for Derivation
source§fn from(d: SoftDerivation) -> Self
fn from(d: SoftDerivation) -> Self
source§impl FromStr for SoftDerivation
impl FromStr for SoftDerivation
source§impl Hash for SoftDerivation
impl Hash for SoftDerivation
source§impl Ord for SoftDerivation
impl Ord for SoftDerivation
source§fn cmp(&self, other: &SoftDerivation) -> Ordering
fn cmp(&self, other: &SoftDerivation) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<SoftDerivation> for SoftDerivation
impl PartialEq<SoftDerivation> for SoftDerivation
source§fn eq(&self, other: &SoftDerivation) -> bool
fn eq(&self, other: &SoftDerivation) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<SoftDerivation> for SoftDerivation
impl PartialOrd<SoftDerivation> for SoftDerivation
source§fn partial_cmp(&self, other: &SoftDerivation) -> Option<Ordering>
fn partial_cmp(&self, other: &SoftDerivation) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more