avr_tester/components/
component_handle.rs

1use super::*;
2use std::cell::RefCell;
3use std::rc::Rc;
4
5pub struct ComponentHandle {
6    state: Rc<RefCell<ComponentState>>,
7}
8
9impl ComponentHandle {
10    pub(crate) fn new(state: Rc<RefCell<ComponentState>>) -> Self {
11        Self { state }
12    }
13
14    /// Pauses component until [`Self::resume()`] is called.
15    pub fn pause(&self) {
16        *self.state.borrow_mut() = ComponentState::Paused;
17    }
18
19    /// Resumes component paused through [`Self::pause()`].
20    pub fn resume(&self) {
21        *self.state.borrow_mut() = ComponentState::Working;
22    }
23
24    /// Removes component, preventing it from running again.
25    pub fn remove(self) {
26        *self.state.borrow_mut() = ComponentState::Removed;
27    }
28
29    /// Returns component's state.
30    pub fn state(&self) -> ComponentState {
31        *self.state.borrow()
32    }
33}