better structure

This commit is contained in:
2025-06-28 03:51:13 +02:00
parent 551a062021
commit f401d4a995
9 changed files with 93 additions and 85 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ use std::{
/// ---------- public API ----------
pub struct StateManager {
recall: fn(Arc<StateManager>),
recall: Box<dyn Fn(&Arc<Self>)>,
store: Mutex<HashMap<usize, Box<dyn Any + Send + Sync>>>,
cursor: Mutex<usize>,
dirty: Mutex<bool>,
@@ -21,9 +21,9 @@ pub struct State<S> {
}
impl StateManager {
pub fn new(recall: fn(Arc<StateManager>)) -> Arc<Self> {
pub fn new<F: Fn(&Arc<Self>) + 'static>(recall: F) -> Arc<Self> {
Arc::new(Self {
recall,
recall: Box::new(recall),
store: Mutex::new(HashMap::new()),
cursor: Mutex::new(0),
dirty: Mutex::new(false),
@@ -49,7 +49,7 @@ impl StateManager {
}
}
pub fn flush(self: Arc<Self>) {
pub fn flush(self: &Arc<Self>) {
let mut d = self.dirty.lock().unwrap();
if *d {
*d = false;