pros_simulator/
interface.rs

1use std::sync::{Arc, Mutex};
2
3use pros_simulator_interface::SimulatorEvent;
4
5#[derive(Clone)]
6pub struct SimulatorInterface {
7    callback: Arc<Mutex<dyn FnMut(SimulatorEvent) + Send>>,
8}
9
10impl<T> From<T> for SimulatorInterface
11where
12    T: FnMut(SimulatorEvent) + Send + 'static,
13{
14    fn from(callback: T) -> Self {
15        Self {
16            callback: Arc::new(Mutex::new(callback)),
17        }
18    }
19}
20
21impl SimulatorInterface {
22    pub(crate) fn send(&self, event: SimulatorEvent) {
23        let mut callback = self.callback.lock().unwrap();
24        callback(event);
25    }
26}