dvcompute_branch/simulation/simulation/
ops.rs1use crate::simulation::simulation::*;
8
9use dvcompute_utils::grc::Grc;
10
11#[must_use = "computations are lazy and do nothing unless to be run"]
13#[derive(Clone)]
14pub struct SimulationFn<T> where T: 'static {
15 gen: Grc<Box<dyn Fn() -> SimulationBox<T>>>
16}
17
18impl<T> SimulationFn<T> {
19
20 #[inline]
22 pub fn new<F, M>(f: F) -> Self
23 where F: Fn() -> M + 'static,
24 M: Simulation<Item = T> + Clone + 'static
25 {
26 SimulationFn {
27 gen: Grc::new(Box::new(move || { f().into_boxed() }))
28 }
29 }
30
31 #[inline]
33 pub fn next(&self) -> SimulationBox<T> {
34 (self.gen)()
35 }
36}