refactor: Mode, View, Bind

This commit is contained in:
i do not exist 2026-07-02 09:21:47 +03:00
parent 51faa82d74
commit 701a651fbd
21 changed files with 901 additions and 880 deletions

27
src/app/config/modes.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::*;
/// Collection of UI modes.
#[derive(Default, Debug, Clone)]
pub struct Modes(
Arc<RwLock<BTreeMap<Arc<str>, Arc<Mode<Arc<str>>>>>>
);
impl Modes {
pub fn add (&self, name: &impl AsRef<str>, body: &impl Language) -> Usually<()> {
let mut mode = Mode::default();
body.each(|item|mode.add(item))?;
self.0.write().unwrap().insert(name.as_ref().into(), Arc::new(mode));
Ok(())
}
pub fn get (&self, name: impl AsRef<str>) -> Option<Arc<Mode<Arc<str>>>> {
self.0.read().unwrap().get(name.as_ref()).cloned()
}
pub fn for_each <T> (&self, mut ator: impl FnMut(&str, &Mode<Arc<str>>)->T) {
for (k, v) in self.0.read().unwrap().iter() {
let _ = ator(k.as_ref(), v.as_ref());
}
}
pub fn len (&self) -> usize {
self.0.read().unwrap().len()
}
}