down to 28e, sane ones

This commit is contained in:
🪞👃🪞 2024-12-31 15:50:53 +01:00
parent 46609855eb
commit 16e6a0397c
15 changed files with 91 additions and 87 deletions

View file

@ -1,4 +1,5 @@
use crate::*;
use std::marker::PhantomData;
//use std::sync::{Arc, Mutex, RwLock};
/// Rendering target
@ -42,54 +43,52 @@ impl<E: Engine, T: Content<E>> Content<E> for Option<T> {}
impl<E: Engine, T: Content<E>> Content<E> for Vec<T> {}
pub struct Thunk<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync>(F, PhantomData<E>);
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Thunk<E, T, F> {
pub fn new (thunk: F) -> Self {
Self(thunk, Default::default())
}
}
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Content<E> for Thunk<E, T, F> {
fn content (&self) -> impl Content<E> {
(self.0)()
}
}
#[macro_export] macro_rules! render {
(($self:ident:$Struct:ty) => $content:expr) => {
impl <E: Engine> Content<E> for $Struct {
fn content (&$self) -> Option<impl Content<E>> {
Some($content)
}
fn content (&$self) -> impl Content<E> { Some($content) }
}
};
(|$self:ident:$Struct:ident $(<
$($L:lifetime),*
$($T:ident $(:$Trait:path)?),*
$($L:lifetime),* $($T:ident $(:$Trait:path)?),*
>)?, $to:ident | $render:expr) => {
impl <$($($L),*)? E: Engine, $($T$(:$Trait)?),*> Content<E>
for $Struct $(<$($L),* $($T),*>>)? {
fn render (&$self, $to: &mut E::Output) {
Some($render)
}
fn render (&$self, $to: &mut E::Output) { $render }
}
};
($Engine:ty:
($self:ident:$Struct:ident $(<$(
$($L:lifetime)?
$($T:ident)?
$(:$Trait:path)?
$($L:lifetime)? $($T:ident)? $(:$Trait:path)?
),+>)?) => $content:expr
) => {
impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Content<$Engine>
for $Struct $(<$($($L)? $($T)?),+>)?
{
fn content (&$self) -> Option<impl Content<$Engine>> {
Some($content)
}
for $Struct $(<$($($L)? $($T)?),+>)? {
fn content (&$self) -> impl Content<$Engine> { $content }
}
};
($Engine:ty:
|$self:ident : $Struct:ident $(<$(
$($L:lifetime)?
$($T:ident)?
$(:$Trait:path)?
$($L:lifetime)? $($T:ident)? $(:$Trait:path)?
),+>)?, $to:ident| $render:expr
) => {
impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Content<$Engine>
for $Struct $(<$($($L)? $($T)?),+>)?
{
fn render (&$self, $to: &mut <$Engine as Engine>::Output) {
Some($render)
}
for $Struct $(<$($($L)? $($T)?),+>)? {
fn render (&$self, $to: &mut <$Engine as Engine>::Output) { $render }
}
};
}