mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
update layout macro invocations
This commit is contained in:
parent
e677d1d7d4
commit
83eb9dd2fa
19 changed files with 153 additions and 169 deletions
|
|
@ -5,6 +5,8 @@ mod stack; pub use self::stack::*;
|
|||
|
||||
use crate::*;
|
||||
|
||||
use std::sync::RwLock;
|
||||
|
||||
/// Conditional rendering, in unary and binary forms.
|
||||
pub struct Cond;
|
||||
|
||||
|
|
@ -17,8 +19,14 @@ impl Cond {
|
|||
pub fn either <E: Engine, A: Content<E>, B: Content<E>> (cond: bool, a: A, b: B) -> Either<E, A, B> {
|
||||
Either(cond, a, b, Default::default())
|
||||
}
|
||||
|
||||
pub fn opt <E: Engine, A, F: Fn(A)->R, R: Content<E>> (option: Option<A>, cb: F) -> Opt<E, A, F, R> {
|
||||
Opt(option, cb, Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Opt<E: Engine, A, F: Fn(A)->R, R: Content<E>>(Option<A>, F, PhantomData<E>);
|
||||
|
||||
/// Contents `self.1` when `self.0` is true.
|
||||
pub struct When<E: Engine, A>(bool, A, PhantomData<E>);
|
||||
|
||||
|
|
@ -62,7 +70,6 @@ pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)
|
|||
impl<E, F> Collector<E> for F
|
||||
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
|
||||
|
||||
/*
|
||||
/// Rendering of iterable collections, one-to-one and many-to one.
|
||||
pub struct Coll;
|
||||
|
||||
|
|
@ -73,24 +80,25 @@ impl Coll {
|
|||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync
|
||||
{
|
||||
Map(Default::default(), iterator, callback)
|
||||
}
|
||||
pub fn reduce <E, T, I, R, F>(iterator: I, callback: F) -> Reduce<E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(R, T, usize) -> R + Send + Sync
|
||||
{
|
||||
Reduce(Default::default(), iterator, callback)
|
||||
Map(Default::default(), RwLock::new(iterator), callback)
|
||||
}
|
||||
//pub fn reduce <E, T, I, R, F>(iterator: I, callback: F) -> Reduce<E, T, I, R, F> where
|
||||
//E: Engine,
|
||||
//I: Iterator<Item = T> + Send + Sync,
|
||||
//R: Content<E>,
|
||||
//F: Fn(R, T, usize) -> R + Send + Sync
|
||||
//{
|
||||
//Reduce(Default::default(), iterator, callback)
|
||||
//}
|
||||
}
|
||||
|
||||
pub struct Map<'a, E, T, I, R, F>(PhantomData<E>, &'a mut I, F) where
|
||||
pub struct Map<E, T, I, R, F>(PhantomData<E>, RwLock<I>, F) where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync;
|
||||
impl<'a, E, T, I, R, F> Content<E> for Map<'a, E, T, I, R, F> where
|
||||
|
||||
impl<E, T, I, R, F> Content<E> for Map<E, T, I, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
R: Content<E>,
|
||||
|
|
@ -98,13 +106,14 @@ impl<'a, E, T, I, R, F> Content<E> for Map<'a, E, T, I, R, F> where
|
|||
{
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
let mut index = 0;
|
||||
for item in self.1 {
|
||||
for item in &mut*self.1.write().unwrap() {
|
||||
(self.2)(item, index).render(to);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub struct Reduce<E, T, I, R, F>(PhantomData<(E, R)>, I, F) where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue