update examples

This commit is contained in:
🪞👃🪞 2025-01-05 22:17:45 +01:00
parent 0e821e098f
commit 400fd9b6e9
9 changed files with 12 additions and 45 deletions

View file

@ -9,6 +9,7 @@ pub type EdnCallback<'a, Output, State> =
pub type EdnRenderCallback<'a, Output, State> =
Box<EdnCallback<'a, Output, State>>;
/// Provides values to the template
pub trait EdnViewData<E: Output> {
fn get_bool (&self, _sym: EdnItem<&str>) -> bool { false }
fn get_unit (&self, _sym: EdnItem<&str>) -> E::Unit { 0.into() }
@ -25,9 +26,11 @@ pub enum EdnView<E: Output, T: EdnViewData<E>> {
}
impl<E: Output, T: EdnViewData<E>> EdnView<E, T> {
pub fn new (context: T, source: &str) -> Usually<Self> {
let layout = EdnItem::read_one(&source)?.0;
Ok(Self::Ok(context, layout))
pub fn new (state: T, source: &str) -> Self {
match EdnItem::read_one(&source) {
Ok((layout, _)) => Self::Ok(state, layout),
Err(error) => Self::Err(format!("{error}"))
}
}
}