check pass, test pass.. but does it run?

This commit is contained in:
🪞👃🪞 2024-12-31 16:39:33 +01:00
parent 1de163d0d3
commit 9f7b23a252
10 changed files with 65 additions and 48 deletions

View file

@ -1,28 +1,47 @@
//! Groupings of elements.
mod split; pub use self::split::*;
mod stack; pub use self::stack::*;
//mod stack; pub use self::stack::*;
use crate::*;
use std::sync::RwLock;
/// Conditional rendering, in unary and binary forms.
pub struct Cond;
impl<E: Engine> Layout<E> for E {}
impl Cond {
pub trait Layout<E: Engine> {
/// Content `item` when `cond` is true.
pub fn when <E: Engine, A: Content<E>> (cond: bool, item: A) -> When<E, A> {
fn when <A: Content<E>> (cond: bool, item: A) -> When<E, A> {
When(cond, item, Default::default())
}
/// Content `item` if `cond` is true, otherwise render `other`.
pub fn either <E: Engine, A: Content<E>, B: Content<E>> (cond: bool, a: A, b: B) -> Either<E, A, B> {
fn either <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> {
/// Maps an [Option<T>] through a callback `F`
fn opt <A, F: Fn(A)->R, R: Content<E>> (option: Option<A>, cb: F)
-> Opt<E, A, F, R>
{
Opt(option, cb, Default::default())
}
fn map <T, I, R, F>(iterator: I, callback: F) -> Map<E, T, I, R, F> where
E: Engine,
I: Iterator<Item = T> + Send + Sync,
R: Content<E>,
F: Fn(T, usize)->R + Send + Sync
{
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 Opt<E: Engine, A, F: Fn(A)->R, R: Content<E>>(Option<A>, F, PhantomData<E>);
@ -63,33 +82,31 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Either<E, A, B> {
}
}
pub trait Render<E: Engine> {
fn area (&self, to: E::Area) -> E::Area;
fn render (&self, to: &mut E::Output);
}
impl<E: Engine, C: Content<E>> Render<E> for C {
fn area (&self, to: E::Area) -> E::Area {
Content::area(self, to)
}
fn render (&self, to: &mut E::Output) {
Content::render(self, to)
}
}
/// A function or closure that emits renderables.
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
pub trait Collector<E: Engine>: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<E>)) {}
/// Any function or closure that emits renderables for the given engine matches [CollectCallback].
impl<E, F> Collector<E> for F
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)) {}
where E: Engine, F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<E>)) {}
/// Rendering of iterable collections, one-to-one and many-to one.
pub struct Coll;
impl Coll {
pub fn map <E, T, I, R, F>(iterator: I, callback: F) -> Map<E, T, I, R, F> where
E: Engine,
I: Iterator<Item = T> + Send + Sync,
R: Content<E>,
F: Fn(T, usize)->R + Send + Sync
{
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<E, T, I, R, F>(PhantomData<E>, RwLock<I>, F) where