Struct ckb_types::core::EpochNumberWithFraction
source · [−]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
sourceimpl EpochNumberWithFraction
impl EpochNumberWithFraction
sourcepub const NUMBER_OFFSET: usize = 0usize
pub const NUMBER_OFFSET: usize = 0usize
TODO(doc): @quake
sourcepub const NUMBER_BITS: usize = 24usize
pub const NUMBER_BITS: usize = 24usize
TODO(doc): @quake
sourcepub const NUMBER_MAXIMUM_VALUE: u64 = 16_777_216u64
pub const NUMBER_MAXIMUM_VALUE: u64 = 16_777_216u64
TODO(doc): @quake
sourcepub const NUMBER_MASK: u64 = 16_777_215u64
pub const NUMBER_MASK: u64 = 16_777_215u64
TODO(doc): @quake
sourcepub const INDEX_OFFSET: usize = 24usize
pub const INDEX_OFFSET: usize = 24usize
TODO(doc): @quake
sourcepub const INDEX_BITS: usize = 16usize
pub const INDEX_BITS: usize = 16usize
TODO(doc): @quake
sourcepub const INDEX_MAXIMUM_VALUE: u64 = 65_536u64
pub const INDEX_MAXIMUM_VALUE: u64 = 65_536u64
TODO(doc): @quake
sourcepub const INDEX_MASK: u64 = 65_535u64
pub const INDEX_MASK: u64 = 65_535u64
TODO(doc): @quake
sourcepub const LENGTH_OFFSET: usize = 40usize
pub const LENGTH_OFFSET: usize = 40usize
TODO(doc): @quake
sourcepub const LENGTH_BITS: usize = 16usize
pub const LENGTH_BITS: usize = 16usize
TODO(doc): @quake
sourcepub const LENGTH_MAXIMUM_VALUE: u64 = 65_536u64
pub const LENGTH_MAXIMUM_VALUE: u64 = 65_536u64
TODO(doc): @quake
sourcepub const LENGTH_MASK: u64 = 65_535u64
pub const LENGTH_MASK: u64 = 65_535u64
TODO(doc): @quake
sourcepub const fn new_unchecked(number: u64, index: u64, length: u64) -> Self
pub const fn new_unchecked(number: u64, index: u64, length: u64) -> Self
TODO(doc): @quake
sourcepub fn number(self) -> EpochNumber
pub fn number(self) -> EpochNumber
TODO(doc): @quake
sourcepub const fn full_value(self) -> u64
pub const fn full_value(self) -> u64
TODO(doc): @quake
sourcepub fn minimum_epoch_number_after_n_blocks(self, n: BlockNumber) -> EpochNumber
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
.
sourcepub fn from_full_value(value: u64) -> Self
pub fn from_full_value(value: u64) -> Self
TODO(doc): @quake
sourcepub fn from_full_value_unchecked(value: u64) -> Self
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.
sourcepub fn normalize(self) -> Self
pub fn normalize(self) -> Self
Prevents leading to a panic if the EpochNumberWithFraction
is constructed without checks.
sourcepub fn to_rational(self) -> RationalU256
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.
sourcepub fn is_successor_of(self, predecessor: Self) -> bool
pub fn is_successor_of(self, predecessor: Self) -> bool
Check if current value is another value’s successor.
sourcepub fn is_well_formed(self) -> bool
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.
sourcepub fn is_well_formed_increment(self) -> bool
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
sourceimpl Clone for EpochNumberWithFraction
impl Clone for EpochNumberWithFraction
sourcefn clone(&self) -> EpochNumberWithFraction
fn clone(&self) -> EpochNumberWithFraction
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for EpochNumberWithFraction
impl Debug for EpochNumberWithFraction
sourceimpl Display for EpochNumberWithFraction
impl Display for EpochNumberWithFraction
sourceimpl FromStr for EpochNumberWithFraction
impl FromStr for EpochNumberWithFraction
sourceimpl Hash for EpochNumberWithFraction
impl Hash for EpochNumberWithFraction
sourceimpl Ord for EpochNumberWithFraction
impl Ord for EpochNumberWithFraction
sourceimpl Pack<Uint64> for EpochNumberWithFraction
impl Pack<Uint64> for EpochNumberWithFraction
sourceimpl PartialEq<EpochNumberWithFraction> for EpochNumberWithFraction
impl PartialEq<EpochNumberWithFraction> for EpochNumberWithFraction
sourcefn eq(&self, other: &EpochNumberWithFraction) -> bool
fn eq(&self, other: &EpochNumberWithFraction) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &EpochNumberWithFraction) -> bool
fn ne(&self, other: &EpochNumberWithFraction) -> bool
This method tests for !=
.
sourceimpl PartialOrd<EpochNumberWithFraction> for EpochNumberWithFraction
impl PartialOrd<EpochNumberWithFraction> for EpochNumberWithFraction
sourcefn partial_cmp(&self, other: &EpochNumberWithFraction) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl Unpack<EpochNumberWithFraction> for Uint64
impl Unpack<EpochNumberWithFraction> for Uint64
sourcefn unpack(&self) -> EpochNumberWithFraction
fn unpack(&self) -> EpochNumberWithFraction
Unpack binary data into rust types.
sourceimpl<'r> Unpack<EpochNumberWithFraction> for Uint64Reader<'r>
impl<'r> Unpack<EpochNumberWithFraction> for Uint64Reader<'r>
sourcefn unpack(&self) -> EpochNumberWithFraction
fn unpack(&self) -> EpochNumberWithFraction
Unpack binary data into rust types.
impl Copy for EpochNumberWithFraction
impl Eq for EpochNumberWithFraction
impl StructuralEq for EpochNumberWithFraction
impl StructuralPartialEq for EpochNumberWithFraction
Auto Trait Implementations
impl RefUnwindSafe for EpochNumberWithFraction
impl Send for EpochNumberWithFraction
impl Sync for EpochNumberWithFraction
impl Unpin for EpochNumberWithFraction
impl UnwindSafe for EpochNumberWithFraction
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more