Clock

Struct Clock 

Source
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: usize

Current step of the simulation

§total: usize

Total steps to run in the simulation

Implementations§

Source§

impl Clock

Source

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
Source

pub fn tick(&mut self) -> Option<usize>

Advances the clock by one step.

§Returns
  • Some(step) - The current step number (starting from 0) before advancing
  • None - If the clock has reached its total steps
Source

pub fn run<F>(&mut self, f: F)
where F: FnMut(usize),

Runs a function for each remaining step in the clock.

This method will call the provided function with the current step number for each step until the clock completes all steps.

§Arguments
  • f - A function that takes the current step number as an argument

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.