use core::marker::PhantomData;
use crate::env::*;
use crate::ream::*;
#[derive(Debug)]
pub struct Book<R> {
phantom_data: PhantomData<R>,
}
pub struct Pages<R>
where
R: Ream,
{
pub ream: R,
pub env: <R as Ream>::Env,
}
impl<R> core::fmt::Debug for Pages<R>
where
R: Ream + core::fmt::Debug,
<R as Ream>::Env: core::fmt::Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Pages")
.field("ream", &self.ream)
.field("env", &self.env)
.finish()
}
}
impl<R> Pages<R>
where
R: Ream + 'static,
{
pub fn bind(self) -> <<R as Ream>::Env as Environment>::Return {
let mut ream = self.ream;
self.env.run(move |proxy| ream.update(proxy))
}
}
impl<R> Book<R>
where
R: Default + Ream + 'static,
<R as Ream>::Env: Default,
{
pub fn pages() -> Pages<R> {
Pages {
ream: R::default(),
env: <R as Ream>::Env::default(),
}
}
pub fn bind() -> <<R as Ream>::Env as Environment>::Return {
Self::pages().bind()
}
}
impl<R> Book<R>
where
R: Ream,
<R as Ream>::Env: Default,
{
pub fn pages_with<I>(input: I) -> Pages<R>
where
R: From<I>,
{
Pages {
ream: R::from(input),
env: <R as Ream>::Env::default(),
}
}
pub fn bind_with<I>(input: I) -> <<R as Ream>::Env as Environment>::Return
where
R: From<I> + 'static,
{
Self::pages_with(input).bind()
}
}