pub struct Clock {
current: usize,
total: usize,
}Expand description
A simulation clock that tracks steps over a fixed duration.
The Clock provides methods to advance time step-by-step or run
a function at each time step until completion.
§Examples
Note: vpp-sim currently ships as a binary-first crate; this snippet is illustrative.
ⓘ
use vpp_sim::sim::clock::Clock;
let mut clock = Clock::new(3);
let mut steps = Vec::new();
clock.run(|step| steps.push(step));
assert_eq!(steps, vec![0, 1, 2]);Fields§
§current: usizeCurrent step of the simulation
total: usizeTotal steps to run in the simulation
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn new(total: usize) -> Self
pub fn new(total: usize) -> Self
Creates a new clock with a specified total number of steps.
§Arguments
total- The total number of steps the clock will run
Sourcepub fn tick(&mut self) -> Option<usize>
pub fn tick(&mut self) -> Option<usize>
Advances the clock by one step.
§Returns
Some(step)- The current step number (starting from 0) before advancingNone- If the clock has reached its total steps
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin for Clock
impl UnwindSafe for Clock
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