mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: providing content chunks with ednprovider
This commit is contained in:
parent
1ff35baea9
commit
8c54f8e426
8 changed files with 157 additions and 41 deletions
|
|
@ -1,34 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
/// Implement `EdnProvide` for a type and context
|
||||
#[macro_export] macro_rules! edn_provide {
|
||||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl EdnProvide<$type> for $State {
|
||||
fn get <S: AsRef<str>> (&$self, edn: &EdnItem<S>) -> Option<$type> {
|
||||
Some(match edn.to_ref() {
|
||||
$(EdnItem::Sym($pat) => $expr),*,
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Map EDN tokens to parameters of a given type for a given context
|
||||
pub trait EdnProvide<U> {
|
||||
fn get <S: AsRef<str>> (&self, _edn: &EdnItem<S>) -> Option<U> {
|
||||
None
|
||||
}
|
||||
fn get_or_fail <S: AsRef<str>> (&self, edn: &EdnItem<S>) -> U {
|
||||
self.get(edn).expect("no value")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EdnProvide<U>, U> EdnProvide<U> for &T {
|
||||
fn get <S: AsRef<str>> (&self, edn: &EdnItem<S>) -> Option<U> {
|
||||
(*self).get(edn)
|
||||
}
|
||||
fn get_or_fail <S: AsRef<str>> (&self, edn: &EdnItem<S>) -> U {
|
||||
(*self).get_or_fail(edn)
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ mod event_map; pub use self::event_map::*;
|
|||
mod edn_command; pub use self::edn_command::*;
|
||||
mod edn_input; pub use self::edn_input::*;
|
||||
mod edn_keymap; pub use self::edn_keymap::*;
|
||||
mod edn_provide; pub use self::edn_provide::*;
|
||||
|
||||
pub(crate) use ::tek_edn::EdnItem;
|
||||
/// Standard error trait.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue