wip: trait EdnCommand

This commit is contained in:
🪞👃🪞 2025-01-12 01:07:01 +01:00
parent 8850fbf2f8
commit aad7aa6c5e
7 changed files with 193 additions and 165 deletions

View file

@ -4,3 +4,4 @@ edition = "2021"
version = "0.2.0"
[dependencies]
tek_edn = { path = "../edn" }

30
input/src/edn_cmd.rs Normal file
View file

@ -0,0 +1,30 @@
use crate::*;
use std::marker::PhantomData;
pub trait EdnControlData<E: Input> {}
/// Renders from EDN source and context.
#[derive(Default)]
pub enum EdnControls<E: Input, T: EdnControlData<E>> {
#[default]
Inert,
_Unused(PhantomData<E>),
Ok(T, EdnItem<String>),
Err(String)
}
impl<E: Input, T: EdnControlData<E>> EdnControls<E, T> {
pub fn from_source (state: T, source: &str) -> Self {
match EdnItem::read_one(&source) {
Ok((layout, _)) => Self::Ok(state, layout),
Err(error) => Self::Err(format!("{error}"))
}
}
pub fn from_items (state: T, items: &[EdnItem<&str>]) -> Self {
Self::Ok(state, EdnItem::Exp(items.iter().map(|i|(*i).clone()).collect()))
}
}
pub trait EdnCommand<C>: Command<C> {
fn from_edn <'a> (state: &C, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self;
}

View file

@ -5,7 +5,9 @@ mod input; pub use self::input::*;
mod handle; pub use self::handle::*;
mod command; pub use self::command::*;
mod event_map; pub use self::event_map::*;
mod edn_cmd; pub use self::edn_cmd::*;
pub(crate) use ::tek_edn::EdnItem;
/// Standard error trait.
pub(crate) use std::error::Error;
/// Standard result type.