pub struct Position<F: Family>(/* private fields */);Expand description
A Position is a node index or node count in a Merkle structure. This is in contrast to a Location, which is a leaf index or leaf count.
§Limits
Values up to the family’s maximum are valid (see Position::is_valid). As a 0-based node
index, valid indices are 0..MAX - 1. As a node count or total size, the maximum is MAX
itself. Use Position::is_valid_size to ask whether a count is a structurally valid size for
the specific Merkle family.
Implementations§
Source§impl<F: Family> Position<F>
impl<F: Family> Position<F>
Sourcepub const fn is_valid(self) -> bool
pub const fn is_valid(self) -> bool
Returns true iff this value is a valid node count or size (<= MAX_NODES).
Sourcepub const fn is_valid_index(self) -> bool
pub const fn is_valid_index(self) -> bool
Returns true iff this value is a valid 0-based node index (< MAX_NODES).
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 the maximum.
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 the maximum.
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 fn is_valid_size(self) -> bool
pub fn is_valid_size(self) -> bool
Returns whether this is a valid size for this Merkle structure.
Trait Implementations§
Source§impl<F: Family> Add<u64> for Position<F>
Add a position and a u64.
impl<F: Family> Add<u64> for Position<F>
Add a position and a u64.
§Panics
Panics if the result overflows.
Source§impl<F: Family> Add for Position<F>
Add two positions together.
impl<F: Family> Add for Position<F>
Add two positions together.
§Panics
Panics if the result overflows.
Source§impl<F: Family> AddAssign<u64> for Position<F>
Add a u64 to a position.
impl<F: Family> AddAssign<u64> for Position<F>
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<F: Family> EncodeSize for Position<F>
impl<F: Family> EncodeSize for Position<F>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
BufsMut::push
during Write::write_bufs. Used to size the working buffer for inline
writes. Override alongside Write::write_bufs for types where large
Bytes fields go via push; failing to do so will over-allocate.Source§impl<F: Family> Ord for Position<F>
impl<F: Family> Ord for Position<F>
Source§impl<F: Family> PartialOrd<Position<F>> for u64
impl<F: Family> PartialOrd<Position<F>> for u64
Source§impl<F: Family> PartialOrd<u64> for Position<F>
impl<F: Family> PartialOrd<u64> for Position<F>
Source§impl<F: Family> PartialOrd for Position<F>
impl<F: Family> PartialOrd for Position<F>
Source§impl<F: Family> Read for Position<F>
impl<F: Family> Read for Position<F>
Source§impl<F: Family> Sub<u64> for Position<F>
Subtract a u64 from a position.
impl<F: Family> Sub<u64> for Position<F>
Subtract a u64 from a position.
§Panics
Panics if the result underflows.
Source§impl<F: Family> Sub for Position<F>
Subtract two positions.
impl<F: Family> Sub for Position<F>
Subtract two positions.
§Panics
Panics if the result underflows.
Source§impl<F: Family> SubAssign<u64> for Position<F>
Subtract a u64 from a position.
impl<F: Family> SubAssign<u64> for Position<F>
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<F: Family> TryFrom<Location<F>> for Position<F>
impl<F: Family> TryFrom<Location<F>> for Position<F>
Equivalently, convert a leaf count to the corresponding total node count (size).
Returns super::Error::LocationOverflow if !loc.is_valid().
Source§impl<F: Family> TryFrom<Position<F>> for Location<F>
impl<F: Family> TryFrom<Position<F>> for Location<F>
Equivalently, convert a total node count (size) to the corresponding leaf count.
Returns an error if pos exceeds the valid range or if it is neither a leaf position nor a
valid size.
Source§impl<F: Family> Write for Position<F>
impl<F: Family> Write for Position<F>
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
BufsMut, allowing existing Bytes chunks to be
appended via BufsMut::push instead of written inline. Must encode
to the same format as Write::write. Defaults to Write::write.impl<F: Family> Copy for Position<F>
impl<F: Family> Eq for Position<F>
Auto Trait Implementations§
impl<F> Freeze for Position<F>
impl<F> RefUnwindSafe for Position<F>where
F: RefUnwindSafe,
impl<F> Send for Position<F>
impl<F> Sync for Position<F>
impl<F> Unpin for Position<F>where
F: Unpin,
impl<F> UnsafeUnpin for Position<F>
impl<F> UnwindSafe for Position<F>where
F: UnwindSafe,
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) -> IoBufs
fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs
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.