mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: namespaces
This commit is contained in:
parent
525a455f7a
commit
f2d6e7724b
4 changed files with 174 additions and 169 deletions
32
crates/app/app_dsl.rs
Normal file
32
crates/app/app_dsl.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use crate::*;
|
||||
|
||||
macro_rules!dsl_sym(
|
||||
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
|
||||
impl<'t> DslSymNs<'t, $type> for $State {
|
||||
const NS: DslNs<'t, fn (&'t $State)->$type> =
|
||||
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
|
||||
|
||||
pub trait DslSymNs<'t, T: 't>: 't {
|
||||
const NS: DslNs<'t, fn (&'t Self)->T>;
|
||||
}
|
||||
|
||||
pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
|
||||
|
||||
pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
|
||||
|
||||
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
||||
type Output = DslCb;
|
||||
fn index (&self, index: D) -> &Self::Output {
|
||||
if let Ok(Some(symbol)) = index.src() {
|
||||
for (key, value) in self.0.iter() {
|
||||
if symbol == *key {
|
||||
return value
|
||||
}
|
||||
}
|
||||
}
|
||||
&(view_nil as DslCb)
|
||||
}
|
||||
}
|
||||
fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
|
||||
Box::new(Fill::xy("·"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue