pub struct EpochNumberWithFraction(_);
Expand description

Represents an epoch number with a fraction unit, it can be used to accurately represent the position for a block within an epoch.

Implementations§

source§

impl EpochNumberWithFraction

source

pub const NUMBER_OFFSET: usize = 0usize

TODO(doc): @quake

source

pub const NUMBER_BITS: usize = 24usize

TODO(doc): @quake

source

pub const NUMBER_MAXIMUM_VALUE: u64 = 16_777_216u64

TODO(doc): @quake

source

pub const NUMBER_MASK: u64 = 16_777_215u64

TODO(doc): @quake

source

pub const INDEX_OFFSET: usize = 24usize

TODO(doc): @quake

source

pub const INDEX_BITS: usize = 16usize

TODO(doc): @quake

source

pub const INDEX_MAXIMUM_VALUE: u64 = 65_536u64

TODO(doc): @quake

source

pub const INDEX_MASK: u64 = 65_535u64

TODO(doc): @quake

source

pub const LENGTH_OFFSET: usize = 40usize

TODO(doc): @quake

source

pub const LENGTH_BITS: usize = 16usize

TODO(doc): @quake

source

pub const LENGTH_MAXIMUM_VALUE: u64 = 65_536u64

TODO(doc): @quake

source

pub const LENGTH_MASK: u64 = 65_535u64

TODO(doc): @quake

source

pub fn new(number: u64, index: u64, length: u64) -> EpochNumberWithFraction

TODO(doc): @quake

source

pub const fn new_unchecked(number: u64, index: u64, length: u64) -> Self

TODO(doc): @quake

source

pub fn number(self) -> EpochNumber

TODO(doc): @quake

source

pub fn index(self) -> u64

TODO(doc): @quake

source

pub fn length(self) -> u64

TODO(doc): @quake

source

pub const fn full_value(self) -> u64

TODO(doc): @quake

source

pub fn minimum_epoch_number_after_n_blocks(self, n: BlockNumber) -> EpochNumber

Estimate the floor limit of epoch number after N blocks.

Since we couldn’t know the length of next epoch before reach the next epoch, this function could only return self.number() or self.number()+1.

source

pub fn from_full_value(value: u64) -> Self

TODO(doc): @quake

source

pub fn from_full_value_unchecked(value: u64) -> Self

Converts from an unsigned 64 bits number without checks.

Notice

The EpochNumberWithFraction constructed by this method has a potential risk that when call self.to_rational() may lead to a panic if the user specifies a zero epoch length.

source

pub fn normalize(self) -> Self

Prevents leading to a panic if the EpochNumberWithFraction is constructed without checks.

source

pub fn to_rational(self) -> RationalU256

Converts the epoch to an unsigned 256 bits rational.

Panics

Only genesis epoch’s length could be zero, otherwise causes a division-by-zero panic.

source

pub fn is_genesis(&self) -> bool

Check if current value is the genesis block.

source

pub fn is_successor_of(self, predecessor: Self) -> bool

Check if current value is another value’s successor.

source

pub fn is_well_formed(self) -> bool

Check the data format.

The epoch length should be greater than zero. The epoch index should be less than the epoch length.

source

pub fn is_well_formed_increment(self) -> bool

Check the data format as an increment.

The epoch index should be less than the epoch length or both of them are zero.

Trait Implementations§

source§

impl Clone for EpochNumberWithFraction

source§

fn clone(&self) -> EpochNumberWithFraction

Returns a copy 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 Debug for EpochNumberWithFraction

source§

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

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

impl Display for EpochNumberWithFraction

source§

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

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

impl FromStr for EpochNumberWithFraction

§

type Err = ParseIntError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for EpochNumberWithFraction

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 Ord for EpochNumberWithFraction

source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl Pack<Uint64> for EpochNumberWithFraction

source§

fn pack(&self) -> Uint64

Packs a rust type into binary data.
source§

impl PartialEq<EpochNumberWithFraction> for EpochNumberWithFraction

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<EpochNumberWithFraction> for EpochNumberWithFraction

source§

fn partial_cmp(&self, other: &EpochNumberWithFraction) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Unpack<EpochNumberWithFraction> for Uint64

source§

fn unpack(&self) -> EpochNumberWithFraction

Unpack binary data into rust types.
source§

impl<'r> Unpack<EpochNumberWithFraction> for Uint64Reader<'r>

source§

fn unpack(&self) -> EpochNumberWithFraction

Unpack binary data into rust types.
source§

impl Copy for EpochNumberWithFraction

source§

impl Eq for EpochNumberWithFraction

source§

impl StructuralEq for EpochNumberWithFraction

source§

impl StructuralPartialEq for EpochNumberWithFraction

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V