mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
30 lines
880 B
Rust
30 lines
880 B
Rust
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;
|
|
}
|