pub struct Executor { /* private fields */ }
Expand description
Executor is used for simple execution of an entire simulation.
See the crate level documentation for examples.
Implementations§
Source§impl Executor
impl Executor
Sourcepub fn unbound() -> Self
pub fn unbound() -> Self
Simulation will end only once there is no available events in the queue.
Examples found in repository?
examples/simulation.rs (line 190)
168fn main() {
169 let messages = Rc::new(RefCell::new(Vec::<String>::new()));
170 let mut simulation = Simulation::default();
171 let queue = simulation.add_queue(Fifo::default());
172 let working_on = simulation.state.insert::<Option<Product>>(None);
173 let consumer = simulation.add_component(Consumer {
174 incoming: queue,
175 working_on,
176 messages: messages.clone(),
177 });
178 let produced_count = simulation.state.insert(0_usize);
179 let producer = simulation.add_component(Producer {
180 outgoing: queue,
181 consumer,
182 produced_count,
183 messages: messages.clone(),
184 });
185 simulation.schedule(Duration::new(0, 0), producer, ProducerEvent);
186 // simulation.schedule(Duration::new(0, 0), consumer, ProducerEvent);
187 // The above would fail with: ^^^^^^^^^^^^^ expected enum `ConsumerEvent`, found struct `ProducerEvent`
188 {
189 let messages = messages.clone();
190 simulation.execute(Executor::unbound().side_effect(move |sim| {
191 messages
192 .borrow_mut()
193 .push(format!("{:?}", sim.scheduler.time()));
194 }));
195 }
196 assert_eq!(*messages.borrow(), EXPECTED.split('\n').collect::<Vec<_>>());
197}
Sourcepub fn timed(time: Duration) -> Self
pub fn timed(time: Duration) -> Self
Simulation will be run no longer than the given time. It may terminate early if no events are available.
Sourcepub fn steps(steps: usize) -> Self
pub fn steps(steps: usize) -> Self
Simulation will execute exactly this many steps, unless we run out of events.
Sourcepub fn side_effect<F>(self, func: F) -> ExecutorWithSideEffect<F>where
F: Fn(&Simulation),
pub fn side_effect<F>(self, func: F) -> ExecutorWithSideEffect<F>where
F: Fn(&Simulation),
Registers a side effect that is called after each simulation step.
Examples found in repository?
examples/simulation.rs (lines 190-194)
168fn main() {
169 let messages = Rc::new(RefCell::new(Vec::<String>::new()));
170 let mut simulation = Simulation::default();
171 let queue = simulation.add_queue(Fifo::default());
172 let working_on = simulation.state.insert::<Option<Product>>(None);
173 let consumer = simulation.add_component(Consumer {
174 incoming: queue,
175 working_on,
176 messages: messages.clone(),
177 });
178 let produced_count = simulation.state.insert(0_usize);
179 let producer = simulation.add_component(Producer {
180 outgoing: queue,
181 consumer,
182 produced_count,
183 messages: messages.clone(),
184 });
185 simulation.schedule(Duration::new(0, 0), producer, ProducerEvent);
186 // simulation.schedule(Duration::new(0, 0), consumer, ProducerEvent);
187 // The above would fail with: ^^^^^^^^^^^^^ expected enum `ConsumerEvent`, found struct `ProducerEvent`
188 {
189 let messages = messages.clone();
190 simulation.execute(Executor::unbound().side_effect(move |sim| {
191 messages
192 .borrow_mut()
193 .push(format!("{:?}", sim.scheduler.time()));
194 }));
195 }
196 assert_eq!(*messages.borrow(), EXPECTED.split('\n').collect::<Vec<_>>());
197}
Trait Implementations§
Source§impl Execute for Executor
impl Execute for Executor
Source§fn execute(self, sim: &mut Simulation)
fn execute(self, sim: &mut Simulation)
Executes the simulation until some stopping condition is reached.
The condition is implementation-specific.
impl Copy for Executor
impl Eq for Executor
impl StructuralPartialEq for Executor
Auto Trait Implementations§
impl Freeze for Executor
impl RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnwindSafe for Executor
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