pub struct Position(/* private fields */);Expand description
Implementations§
Source§impl Position
impl Position
Sourcepub const fn is_valid(self) -> bool
pub const fn is_valid(self) -> bool
Returns true iff this value is within the valid range (<= MAX_POSITION).
This covers both node indices (< MAX_POSITION) and node counts (<= MAX_POSITION).
Sourcepub const fn checked_add(self, rhs: u64) -> Option<Self>
pub const fn checked_add(self, rhs: u64) -> Option<Self>
Return self + rhs returning None on overflow or if result exceeds MAX_POSITION.
Sourcepub const fn checked_sub(self, rhs: u64) -> Option<Self>
pub const fn checked_sub(self, rhs: u64) -> Option<Self>
Return self - rhs returning None on underflow.
Sourcepub const fn saturating_add(self, rhs: u64) -> Self
pub const fn saturating_add(self, rhs: u64) -> Self
Return self + rhs saturating at MAX_POSITION.
Sourcepub const fn saturating_sub(self, rhs: u64) -> Self
pub const fn saturating_sub(self, rhs: u64) -> Self
Return self - rhs saturating at zero.
Sourcepub const fn is_mmr_size(self) -> bool
pub const fn is_mmr_size(self) -> bool
Returns whether this is a valid MMR size.
The implementation verifies that (1) the size won’t result in overflow and (2) peaks in the MMR of the given size have strictly decreasing height, which is a necessary condition for MMR validity.
Trait Implementations§
Source§impl AddAssign<u64> for Position
Add a u64 to a position.
impl AddAssign<u64> for Position
Add a u64 to a position.
§Panics
Panics if the result overflows.
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+= operation. Read moreSource§impl EncodeSize for Position
impl EncodeSize for Position
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§impl Ord for Position
impl Ord for Position
Source§impl PartialOrd<Position> for u64
impl PartialOrd<Position> for u64
Source§impl PartialOrd<u64> for Position
impl PartialOrd<u64> for Position
Source§impl PartialOrd for Position
impl PartialOrd for Position
Source§impl Read for Position
impl Read for Position
Source§impl Sub<u64> for Position
Subtract a u64 from a position.
impl Sub<u64> for Position
Subtract a u64 from a position.
§Panics
Panics if the result underflows.
Source§impl SubAssign<u64> for Position
Subtract a u64 from a position.
impl SubAssign<u64> for Position
Subtract a u64 from a position.
§Panics
Panics if the result underflows.
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-= operation. Read moreSource§impl TryFrom<Location> for Position
impl TryFrom<Location> for Position
Returns super::Error::LocationOverflow if !loc.is_valid().
§Examples
use commonware_storage::mmr::{Location, Position, MAX_LOCATION};
use core::convert::TryFrom;
let loc = Location::new(5);
let pos = Position::try_from(loc).unwrap();
assert_eq!(pos, Position::new(8));
// MAX_LOCATION converts successfully (it is the leaf count for 2^62 leaves)
let pos = Position::try_from(MAX_LOCATION).unwrap();
assert!(pos.is_valid());Source§impl TryFrom<Position> for Location
impl TryFrom<Position> for Location
impl Copy for Position
impl Eq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Encode for Twhere
T: Write + EncodeSize,
impl<T> Encode for Twhere
T: Write + EncodeSize,
Source§impl<T> EncodeExt for Twhere
T: EncodeSize + Write,
impl<T> EncodeExt for Twhere
T: EncodeSize + Write,
Source§fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
Source§fn encode_with_pool(&self, pool: &BufferPool) -> IoBuf
fn encode_with_pool(&self, pool: &BufferPool) -> IoBuf
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.