pub struct Scheduler { /* private fields */ }Expand description
Deterministic event scheduler for simulation.
Processes events in timestamp order with deterministic tie-breaking. All randomness goes through the seeded RNG.
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn with_config(seed: u64, config: SchedulerConfig) -> Self
pub fn with_config(seed: u64, config: SchedulerConfig) -> Self
Creates a new scheduler with the given seed and configuration.
Sourcepub fn time(&self) -> &VirtualTime
pub fn time(&self) -> &VirtualTime
Returns a reference to the virtual time.
Sourcepub fn time_mut(&mut self) -> &mut VirtualTime
pub fn time_mut(&mut self) -> &mut VirtualTime
Returns a mutable reference to the virtual time.
Sourcepub fn rng(&self) -> &SimulationRng
pub fn rng(&self) -> &SimulationRng
Returns a reference to the RNG.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of pending events.
Sourcepub fn clear_event_log(&mut self)
pub fn clear_event_log(&mut self)
Clears the event log.
Sourcepub fn schedule_at(&mut self, timestamp: u64, event_type: EventType) -> EventId
pub fn schedule_at(&mut self, timestamp: u64, event_type: EventType) -> EventId
Schedules an event at the given absolute timestamp.
Sourcepub fn schedule_after(
&mut self,
delay: Duration,
event_type: EventType,
) -> EventId
pub fn schedule_after( &mut self, delay: Duration, event_type: EventType, ) -> EventId
Schedules an event after the given delay from now.
Sourcepub fn schedule_now(&mut self, event_type: EventType) -> EventId
pub fn schedule_now(&mut self, event_type: EventType) -> EventId
Schedules an event at the current time.
Sourcepub fn cancel(&mut self, id: EventId) -> bool
pub fn cancel(&mut self, id: EventId) -> bool
Cancels a pending event by ID.
Returns true if the event was found and cancelled.
Sourcepub fn next_event_time(&self) -> Option<u64>
pub fn next_event_time(&self) -> Option<u64>
Returns the timestamp of the next pending event, if any.
Sourcepub fn step(&mut self) -> Option<Event>
pub fn step(&mut self) -> Option<Event>
Processes the next pending event, advancing time if necessary.
Returns the processed event, or None if no events are pending.
Sourcepub fn run_until<F>(&mut self, condition: F) -> usize
pub fn run_until<F>(&mut self, condition: F) -> usize
Processes events until the given condition is true or no events remain.
Returns the number of events processed.
Sourcepub fn run_until_time(&mut self, target_time: u64) -> usize
pub fn run_until_time(&mut self, target_time: u64) -> usize
Processes events until the given time is reached.
Returns the number of events processed.
Sourcepub fn run_all(&mut self) -> usize
pub fn run_all(&mut self) -> usize
Processes all pending events.
Returns the number of events processed.
Sourcepub fn drain_pending(&mut self) -> Vec<Event>
pub fn drain_pending(&mut self) -> Vec<Event>
Drains all pending events without processing them.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scheduler
impl RefUnwindSafe for Scheduler
impl Send for Scheduler
impl Sync for Scheduler
impl Unpin for Scheduler
impl UnwindSafe for Scheduler
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.