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
use std::io::Write;
macro_rules! render {
($template:path) => (Render(|o| $template(o)));
($template:path, $($arg:expr),*) => {{
use self::actix_ructe::Render;
Render(|o| $template(o, $($arg),*))
}};
($template:path, $($arg:expr),* ,) => {{
use self::actix_ructe::Render;
Render(|o| $template(o, $($arg),*))
}};
}
pub struct Render<T: FnOnce(&mut dyn Write) -> std::io::Result<()>>(pub T);
impl<T: FnOnce(&mut dyn Write) -> std::io::Result<()>> From<Render<T>>
for actix_web::body::Body
{
fn from(t: Render<T>) -> Self {
let mut buf = Vec::new();
match t.0(&mut buf) {
Ok(()) => buf.into(),
Err(_e) => {
"Render failed".into()
}
}
}
}