Struct chain_path_derivation::HardDerivation
source · pub struct HardDerivation(Derivation);
Expand description
wrapper to guarantee the given derivation is a soft derivation
Tuple Fields§
§0: Derivation
Implementations§
source§impl HardDerivation
impl HardDerivation
sourcepub const fn new_unchecked(derivation: Derivation) -> Self
pub const fn new_unchecked(derivation: Derivation) -> Self
construct a hard derivation from the given derivation without checking the derivation is actually a hard 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 hard derivation from the given Derivation
. If the value
is not a hard derivation it will return an error
Example
let derivation = Derivation::new(0x8000_0001);
let derivation = HardDerivation::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 = HardDerivation::max_value();
assert_eq!(max, HardDerivation::new_unchecked(Derivation::new(0xFFFF_FFFF)));
sourcepub const fn min_value() -> Self
pub const fn min_value() -> Self
returns the min derivation index value
let min = HardDerivation::min_value();
assert_eq!(min, HardDerivation::new_unchecked(Derivation::new(0x8000_0000)));
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!(
HardDerivation::new_unchecked(Derivation::new(0x8000_0005)).overflowing_add(2),
(HardDerivation::new_unchecked(Derivation::new(0x8000_0007)), false)
);
assert_eq!(
HardDerivation::max_value().overflowing_add(1),
(HardDerivation::new_unchecked(Derivation::new(0x8000_0000)), 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!(
HardDerivation::new_unchecked(Derivation::new(0x8000_0100)).saturating_add(1),
HardDerivation::new_unchecked(Derivation::new(0x8000_0101))
);
assert_eq!(
HardDerivation::max_value().saturating_add(2048),
HardDerivation::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!(
HardDerivation::new_unchecked(Derivation::new(0x8000_0100)).checked_add(1),
Some(HardDerivation::new_unchecked(Derivation::new(0x8000_0101)))
);
assert_eq!(
HardDerivation::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!(
HardDerivation::new_unchecked(Derivation::new(0x8000_0100)).wrapping_add(1),
HardDerivation::new_unchecked(Derivation::new(0x8000_0101))
);
assert_eq!(
HardDerivation::max_value().wrapping_add(1),
HardDerivation::new_unchecked(Derivation::new(0x8000_0000)),
);
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 HardDerivation
impl Clone for HardDerivation
source§fn clone(&self) -> HardDerivation
fn clone(&self) -> HardDerivation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for HardDerivation
impl Debug for HardDerivation
source§impl Default for HardDerivation
impl Default for HardDerivation
source§impl Deref for HardDerivation
impl Deref for HardDerivation
source§impl Display for HardDerivation
impl Display for HardDerivation
source§impl From<HardDerivation> for Derivation
impl From<HardDerivation> for Derivation
source§fn from(d: HardDerivation) -> Self
fn from(d: HardDerivation) -> Self
source§impl FromStr for HardDerivation
impl FromStr for HardDerivation
source§impl Hash for HardDerivation
impl Hash for HardDerivation
source§impl Ord for HardDerivation
impl Ord for HardDerivation
source§fn cmp(&self, other: &HardDerivation) -> Ordering
fn cmp(&self, other: &HardDerivation) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<HardDerivation> for HardDerivation
impl PartialEq<HardDerivation> for HardDerivation
source§fn eq(&self, other: &HardDerivation) -> bool
fn eq(&self, other: &HardDerivation) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<HardDerivation> for HardDerivation
impl PartialOrd<HardDerivation> for HardDerivation
source§fn partial_cmp(&self, other: &HardDerivation) -> Option<Ordering>
fn partial_cmp(&self, other: &HardDerivation) -> 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