Skip to main content

Position

Struct Position 

Source
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>

Source

pub const fn new(pos: u64) -> Self

Return a new Position from a raw u64.

Source

pub const fn as_u64(self) -> u64

Return the underlying u64 value.

Source

pub const fn is_valid(self) -> bool

Returns true iff this value is a valid node count or size (<= MAX_NODES).

Source

pub const fn is_valid_index(self) -> bool

Returns true iff this value is a valid 0-based node index (< MAX_NODES).

Source

pub const fn checked_add(self, rhs: u64) -> Option<Self>

Return self + rhs returning None on overflow or if result exceeds the maximum.

Source

pub const fn checked_sub(self, rhs: u64) -> Option<Self>

Return self - rhs returning None on underflow.

Source

pub const fn saturating_add(self, rhs: u64) -> Self

Return self + rhs saturating at the maximum.

Source

pub const fn saturating_sub(self, rhs: u64) -> Self

Return self - rhs saturating at zero.

Source

pub fn is_valid_size(self) -> bool

Returns whether this is a valid size for this Merkle structure.

Methods from Deref<Target = u64>§

1.43.0 · Source

pub const MIN: u64 = 0

1.43.0 · Source

pub const MAX: u64

1.53.0 · Source

pub const BITS: u32

Trait Implementations§

Source§

impl<F: Family> Add<u64> for Position<F>

Add a position and a u64.

§Panics

Panics if the result overflows.

Source§

type Output = Position<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u64) -> Self::Output

Performs the + operation. Read more
Source§

impl<F: Family> Add for Position<F>

Add two positions together.

§Panics

Panics if the result overflows.

Source§

type Output = Position<F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

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)

Performs the += operation. Read more
Source§

impl<F: Family> AsRef<u64> for Position<F>

Source§

fn as_ref(&self) -> &u64

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<F: Family> Clone for Position<F>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Family> Debug for Position<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Family> Default for Position<F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F: Family> Deref for Position<F>

Source§

type Target = u64

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<F: Family> Display for Position<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Family> EncodeSize for Position<F>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

fn encode_inline_size(&self) -> usize

Returns the encoded size excluding bytes passed to 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> From<Position<F>> for u64

Source§

fn from(position: Position<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: Family> From<u64> for Position<F>

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl<F: Family> From<usize> for Position<F>

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl<F: Family> Hash for Position<F>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<F: Family> Ord for Position<F>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<F: Family> PartialEq<Position<F>> for u64

Source§

fn eq(&self, other: &Position<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Family> PartialEq<u64> for Position<F>

Source§

fn eq(&self, other: &u64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Family> PartialEq for Position<F>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Family> PartialOrd<Position<F>> for u64

Source§

fn partial_cmp(&self, other: &Position<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F: Family> PartialOrd<u64> for Position<F>

Source§

fn partial_cmp(&self, other: &u64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F: Family> PartialOrd for Position<F>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F: Family> Read for Position<F>

Source§

type Cfg = ()

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, _: &()) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<F: Family> Sub<u64> for Position<F>

Subtract a u64 from a position.

§Panics

Panics if the result underflows.

Source§

type Output = Position<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u64) -> Self::Output

Performs the - operation. Read more
Source§

impl<F: Family> Sub for Position<F>

Subtract two positions.

§Panics

Panics if the result underflows.

Source§

type Output = Position<F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

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)

Performs the -= operation. Read more
Source§

impl<F: Family> TryFrom<Location<F>> for Position<F>

Convert a leaf Location to its corresponding node Position.

Equivalently, convert a leaf count to the corresponding total node count (size).

Returns super::Error::LocationOverflow if !loc.is_valid().

Source§

type Error = Error<F>

The type returned in the event of a conversion error.
Source§

fn try_from(loc: Location<F>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<F: Family> TryFrom<Position<F>> for Location<F>

Attempt to derive the Location of a given node Position.

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§

type Error = Error<F>

The type returned in the event of a conversion error.
Source§

fn try_from(pos: Position<F>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<F: Family> Write for Position<F>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

fn write_bufs(&self, buf: &mut impl BufsMut)

Writes to a 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.
Source§

impl<F: Family> Copy for Position<F>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<X, T> DecodeExt<X> for T
where X: IsUnit, T: Decode<Cfg = X>,

Source§

fn decode(buf: impl Buf) -> Result<Self, Error>

Decodes a value using the default () config.
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> Bytes

Encodes self into a new Bytes buffer. Read more
Source§

fn encode_mut(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
Source§

impl<T> EncodeExt for T
where T: EncodeSize + Write,

Source§

fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut

Encode this value into an IoBufMut allocated from pool. Read more
Source§

fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs

Encode into IoBufs using pool allocation. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ReadExt for T
where T: Read<Cfg = ()>,

Source§

fn read(buf: &mut impl Buf) -> Result<Self, Error>

Reads a value using the default () config.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Codec for T
where T: Encode + Decode,

Source§

impl<T> CodecShared for T
where T: Codec + Send + Sync,

Source§

impl<T> EncodeShared for T
where T: Encode + Send + Sync,

Source§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
where T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> VariableValue for T
where T: CodecShared + Clone,