mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: trait EdnCommand
This commit is contained in:
parent
8850fbf2f8
commit
aad7aa6c5e
7 changed files with 193 additions and 165 deletions
|
|
@ -4,3 +4,4 @@ edition = "2021"
|
|||
version = "0.2.0"
|
||||
|
||||
[dependencies]
|
||||
tek_edn = { path = "../edn" }
|
||||
|
|
|
|||
30
input/src/edn_cmd.rs
Normal file
30
input/src/edn_cmd.rs
Normal 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;
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue