rshtml 0.6.1

RsHtml: A Template Engine for Seamless HTML and Rust Integration.
Documentation
use crate::{View, Write};
use std::{fmt, ops::Deref};

pub struct ViewFn<T>(pub T, usize);

impl<T> ViewFn<T> {
    pub fn new(c: (T, usize)) -> Self {
        Self(c.0, c.1)
    }
}

impl<T> View for ViewFn<T>
where
    T: Fn(&mut dyn Write) -> fmt::Result,
{
    fn render(&self, out: &mut dyn Write) -> fmt::Result {
        (self.0)(out.raw())
    }

    fn text_size(&self) -> usize {
        self.1
    }
}

impl<'a, T> ViewFn<T>
where
    T: Fn(&mut dyn Write) -> fmt::Result + 'a,
{
    pub fn boxed(self) -> Box<dyn View + 'a> {
        Box::new(self)
    }
}

impl<T> Deref for ViewFn<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}