Struct massa_models::slot::Slot
source · pub struct Slot {
pub period: u64,
pub thread: u8,
}
Expand description
a point in time where a block is expected
Fields§
§period: u64
period
thread: u8
thread
Implementations§
source§impl Slot
impl Slot
sourcepub fn new_last_of_cycle(
cycle: u64,
periods_per_cycle: u64,
thread_count: u8
) -> Result<Slot, ModelsError>
pub fn new_last_of_cycle( cycle: u64, periods_per_cycle: u64, thread_count: u8 ) -> Result<Slot, ModelsError>
create the last slot of a given cycle
sourcepub fn new_first_of_cycle(
cycle: u64,
periods_per_cycle: u64
) -> Result<Slot, ModelsError>
pub fn new_first_of_cycle( cycle: u64, periods_per_cycle: u64 ) -> Result<Slot, ModelsError>
create the first slot of a given cycle
sourcepub fn get_first_bit(&self) -> bool
pub fn get_first_bit(&self) -> bool
first bit of the slot, for seed purpose
sourcepub fn is_last_of_cycle(&self, periods_per_cycle: u64, thread_count: u8) -> bool
pub fn is_last_of_cycle(&self, periods_per_cycle: u64, thread_count: u8) -> bool
check if the slot is last in the cycle
sourcepub fn is_first_of_cycle(&self, periods_per_cycle: u64) -> bool
pub fn is_first_of_cycle(&self, periods_per_cycle: u64) -> bool
check if the slot is first in the cycle
sourcepub fn to_bytes_key(&self) -> [u8; 9]
pub fn to_bytes_key(&self) -> [u8; 9]
Returns a fixed-size sortable binary key
Example
let slot = Slot::new(10,5);
let key = slot.to_bytes_key();
let res = Slot::from_bytes_key(&key);
assert_eq!(slot, res);
sourcepub fn from_bytes_key(buffer: &[u8; 9]) -> Self
pub fn from_bytes_key(buffer: &[u8; 9]) -> Self
Deserializes a slot from its fixed-size sortable binary key representation
Example
let slot = Slot::new(10,5);
let key = slot.to_bytes_key();
let res = Slot::from_bytes_key(&key);
assert_eq!(slot, res);
sourcepub fn get_next_slot(&self, thread_count: u8) -> Result<Slot, ModelsError>
pub fn get_next_slot(&self, thread_count: u8) -> Result<Slot, ModelsError>
Returns the next Slot
Example
let slot = Slot::new(10,3);
assert_eq!(slot.get_next_slot(5).unwrap(), Slot::new(10, 4));
let slot = Slot::new(10,4);
assert_eq!(slot.get_next_slot(5).unwrap(), Slot::new(11, 0));
sourcepub fn get_prev_slot(&self, thread_count: u8) -> Result<Slot, ModelsError>
pub fn get_prev_slot(&self, thread_count: u8) -> Result<Slot, ModelsError>
Returns the previous Slot
Example
let slot = Slot::new(10,1);
assert_eq!(slot.get_prev_slot(5).unwrap(), Slot::new(10, 0));
let slot = Slot::new(10,0);
assert_eq!(slot.get_prev_slot(5).unwrap(), Slot::new(9, 4));
sourcepub fn slots_since(
&self,
s: &Slot,
thread_count: u8
) -> Result<u64, ModelsError>
pub fn slots_since( &self, s: &Slot, thread_count: u8 ) -> Result<u64, ModelsError>
Counts the number of slots since the one passed in parameter and until self
If the two slots are equal, the returned value is 0
.
If the passed slot is strictly higher than self, an error is returned
Trait Implementations§
source§impl<'de> Deserialize<'de> for Slot
impl<'de> Deserialize<'de> for Slot
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Deserializer<Slot> for SlotDeserializer
impl Deserializer<Slot> for SlotDeserializer
source§fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
&self,
buffer: &'a [u8]
) -> IResult<&'a [u8], Slot, E>
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8] ) -> IResult<&'a [u8], Slot, E>
use std::ops::Bound::Included;
use massa_serialization::{Serializer, Deserializer, DeserializeError};
use massa_models::slot::{Slot, SlotSerializer, SlotDeserializer};
let slot: Slot = Slot::new(1, 3);
let mut serialized = Vec::new();
let serializer = SlotSerializer::new();
let deserializer = SlotDeserializer::new((Included(u64::MIN), Included(u64::MAX)), (Included(u8::MIN), Included(u8::MAX.into())));
serializer.serialize(&slot, &mut serialized).unwrap();
let (rest, slot_deser) = deserializer.deserialize::<DeserializeError>(&serialized).unwrap();
assert!(rest.is_empty());
assert_eq!(slot, slot_deser);
source§impl Ord for Slot
impl Ord for Slot
source§impl PartialEq<Slot> for Slot
impl PartialEq<Slot> for Slot
source§impl PartialOrd<Slot> for Slot
impl PartialOrd<Slot> for Slot
1.0.0 · source§fn 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 moresource§impl Serializer<Slot> for SlotSerializer
impl Serializer<Slot> for SlotSerializer
source§fn serialize(
&self,
value: &Slot,
buffer: &mut Vec<u8>
) -> Result<(), SerializeError>
fn serialize( &self, value: &Slot, buffer: &mut Vec<u8> ) -> Result<(), SerializeError>
use std::ops::Bound::Included;
use massa_serialization::Serializer;
use massa_models::slot::{Slot, SlotSerializer};
let slot: Slot = Slot::new(1, 3);
let mut serialized = Vec::new();
let serializer = SlotSerializer::new();
serializer.serialize(&slot, &mut serialized).unwrap();
impl Copy for Slot
impl Eq for Slot
impl StructuralEq for Slot
impl StructuralPartialEq for Slot
Auto Trait Implementations§
impl RefUnwindSafe for Slot
impl Send for Slot
impl Sync for Slot
impl Unpin for Slot
impl UnwindSafe for Slot
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
Mutably borrows from an owned value. Read more
§impl<T> Conv for T
impl<T> Conv for T
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
Causes
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
Causes
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
Causes
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
Causes
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
Causes
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
Causes
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
Causes
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
Causes
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
Borrows
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
Mutably borrows
self
, then passes self.as_mut()
into the pipe
function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Immutable access to the
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
Mutable access to the
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
Immutable access to the
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
Mutable access to the
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Immutable access to the
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Mutable access to the
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
Calls
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.