wip: examples for the edn rendering

This commit is contained in:
🪞👃🪞 2025-01-05 04:25:31 +01:00
parent 433e4df0f2
commit 174a7ee614
9 changed files with 51 additions and 30 deletions

4
edn/README.md Normal file
View file

@ -0,0 +1,4 @@
# `tek_edn`
parser and bindings for tek's configuration language,
which is based on edn.

8
edn/examples/edn01.rs Normal file
View file

@ -0,0 +1,8 @@
use tek_edn::*;
const SOURCE: &'static str = include_str!("edn01.edn");
fn main () {
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
Ok(())
}

8
edn/examples/edn02.rs Normal file
View file

@ -0,0 +1,8 @@
use tek_edn::*;
const SOURCE: &'static str = include_str!("edn02.edn");
fn main () {
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
Ok(())
}

View file

@ -1,20 +0,0 @@
use crate::*;
use std::marker::PhantomData;
use ::tek_layout::{*, tek_engine::{Usually, Content, Render, Engine, Thunk}};
use EdnItem::*;
pub type EdnRender<'a, Engine> =
dyn Render<Engine> + Send + Sync + 'a;
pub type EdnCallback<'a, Engine, State> =
dyn Fn(&'a State)->Box<EdnRender<'a, Engine>> + Send + Sync + 'a;
pub type EdnRenderCallback<'a, Engine, State> =
Box<EdnCallback<'a, Engine, State>>;
pub trait EdnLayout<'a, E: Engine + 'a> where Self: 'a {
fn get_bool (&self, _sym: &str) -> bool { false }
fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() }
fn get_usize (&self, _sym: &str) -> usize { 0 }
fn get_content (&'a self, _sym: &str) -> Box<EdnRender<'a, E>> { Box::new(()) }
}

View file

@ -1,22 +1,40 @@
use crate::*;
use std::marker::PhantomData;
use ::tek_layout::{*, tek_engine::{Usually, Content, Render, Engine, Thunk}};
use EdnItem::*;
pub type EdnRender<'a, Engine> =
dyn Render<Engine> + Send + Sync + 'a;
pub type EdnCallback<'a, Engine, State> =
dyn Fn(&'a State)->Box<EdnRender<'a, Engine>> + Send + Sync + 'a;
pub type EdnRenderCallback<'a, Engine, State> =
Box<EdnCallback<'a, Engine, State>>;
pub trait EdnLayout<E: Engine> {
fn get_bool (&self, _sym: &str) -> bool { false }
fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() }
fn get_usize (&self, _sym: &str) -> usize { 0 }
fn get_content <'a> (&'a self, _sym: &str) -> Box<EdnRender<'a, E>> { Box::new(()) }
}
/// Renders from EDN source and context.
pub struct EdnView<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> {
_engine: PhantomData<&'a E>,
pub struct EdnView<E: Engine, T: EdnLayout<E>> {
_engine: PhantomData<E>,
context: T,
layout: EdnItem<String>
//render: Box<dyn Fn(&'a T)->Box<dyn Render<E> + Send + Sync + 'a> + Send + Sync + 'a>
}
impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + 'a> EdnView<'a, E, T> {
pub fn new (context: T, source: &'a str) -> Usually<Self> {
impl<E: Engine, T: EdnLayout<E>> EdnView<E, T> {
pub fn new (context: T, source: &str) -> Usually<Self> {
let layout = EdnItem::read_one(&source)?.0;
Ok(Self { _engine: Default::default(), context, layout, })
}
}
impl<'a, E: Engine + 'a, T: EdnLayout<'a, E> + Send + Sync + 'a> Content<E> for EdnView<'a, E, T> {
impl<E: Engine, T: EdnLayout<E> + Send + Sync> Content<E> for EdnView<E, T> {
fn content (&self) -> impl Render<E> {
use EdnItem::*;
match &self.layout {

View file

@ -11,7 +11,6 @@ pub(crate) use ::tek_layout::{
mod edn_error; pub use self::edn_error::*;
mod edn_item; pub use self::edn_item::*;
mod edn_layout; pub use self::edn_layout::*;
mod edn_token; pub use self::edn_token::*;
mod edn_view; pub use self::edn_view::*;