Struct chain_time::timeframe::TimeFrame
source · pub struct TimeFrame {
timeline: Timeline,
pub(crate) slot_offset: Slot,
slot_duration: SlotDuration,
}
Expand description
Time frame which is a timeline that is configured to be split in discrete slots
Fields§
§timeline: Timeline
§slot_offset: Slot
§slot_duration: SlotDuration
Implementations§
source§impl TimeFrame
impl TimeFrame
sourcepub fn new(timeline: Timeline, per_slot: SlotDuration) -> Self
pub fn new(timeline: Timeline, per_slot: SlotDuration) -> Self
Create a new time frame with a specific slot size
0 1 2 3 4 5
x--------x--------x--------x--------x--------x frame ticking at per_slot
^
|
timeline
sourcepub fn change_frame(&self, slot: Slot, duration_per_slot: SlotDuration) -> Self
pub fn change_frame(&self, slot: Slot, duration_per_slot: SlotDuration) -> Self
Change time frame at a specific slot
Note this also change the beginning of this time frame, to start
0 1 2 3 4 5
x--------x--------┳--------x--------x--------x frame ticking at SlotDuration::from_secs(9)
|
┕---x---x---x---x---x returned frame
2 3 4 5 6 7
↑
|
frame.change_frame(Slot(2), SlotDuration::from_secs(4))
sourcepub fn slot_at_precise(&self, at: &SystemTime) -> Option<SlotAndDuration>
pub fn slot_at_precise(&self, at: &SystemTime) -> Option<SlotAndDuration>
Given a system time get the slot and associated duration leftover
sourcepub fn slot_at(&self, at: &SystemTime) -> Option<Slot>
pub fn slot_at(&self, at: &SystemTime) -> Option<Slot>
Get the slot associated with the given system time.
It returns None if the system time doesn’t represent a valid slot in this time frame, for example if the system time is before the time frame starting point.
sourcepub fn slot_to_systemtime(&self, slot: Slot) -> Option<SystemTime>
pub fn slot_to_systemtime(&self, slot: Slot) -> Option<SystemTime>
Get the system time associated with a slot on a specific timeframe
Note if the slot is not supposed to be in this reference frame, then None is returned
sourcepub fn slot_duration(&self) -> u64
pub fn slot_duration(&self) -> u64
Returns slot duration value.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for TimeFrame
impl Send for TimeFrame
impl Sync for TimeFrame
impl Unpin for TimeFrame
impl UnwindSafe for TimeFrame
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