1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::{fmt, io};

pub use yarte_derive::Template;
pub use yarte_helpers::{helpers::MarkupAsStr, Error, Result};

pub mod rerun;

// TODO: document
pub trait Template: fmt::Display {
    fn call(&self) -> Result<String> {
        let mut buf = String::with_capacity(Self::size_hint());
        self.call_into_fmt(&mut buf).map(|_| buf)
    }

    fn call_into_fmt(&self, writer: &mut fmt::Write) -> fmt::Result {
        write!(writer, "{}", self)
    }

    fn call_into_io(&self, writer: &mut io::Write) -> io::Result<()> {
        write!(writer, "{}", self)
    }

    fn mime() -> &'static str
    where
        Self: Sized;

    fn size_hint() -> usize;
}

#[cfg(feature = "with-actix-web")]
pub mod actix_web {
    pub use actix_web::{
        error::ErrorInternalServerError, Error, HttpRequest, HttpResponse, Responder,
    };
}