load up to modes

the stacked modal music editor. lol
This commit is contained in:
🪞👃🪞 2025-08-10 14:22:22 +03:00
parent b991a49ad7
commit 4d4c470a81
7 changed files with 220 additions and 205 deletions

View file

@ -1,8 +1,23 @@
use crate::*;
/// Namespace. Currently linearly searched.
pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
pub trait DslSymNs<'t, T: 't>: 't { const NS: DslNs<'t, fn (&'t Self)->T>; }
/// Namespace where keys are symbols.
pub trait DslSymNs<'t, T: 't>: 't {
const NS: DslNs<'t, fn (&'t Self)->T>;
fn from_sym <D: Dsl> (&'t self, dsl: D) -> Usually<T> {
if let Some(dsl) = dsl.sym()? {
for (sym, get) in Self::NS.0 {
if dsl == *sym {
return Ok(get(self))
}
}
}
return Err(format!("not found: sym: {dsl:?}").into())
}
}
#[macro_export] macro_rules! dsl_sym (
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
impl<'t> DslSymNs<'t, $type> for $State {