ic_pluto/
view.rs

1/// A helper macro for quickly rendering a view inside a route call.
2///
3/// # Example
4///
5///
6#[macro_export]
7macro_rules! render_view {
8    (
9        $view:path
10        $(, $arg:expr)*
11    ) => {
12        let mut headers = HashMap::from([
13            ("Content-Type".to_string(), "text/html".to_string()),
14        ]);
15        let mut buffer: Vec<u8> = Vec::new();
16        $view(&mut buffer$(, $arg)*).unwrap();
17        return Ok(pluto::http::HttpResponse {
18            status_code: 200,
19            headers,
20            body: pluto::http::HttpBody::String(String::from_utf8(buffer).unwrap()),
21        })
22    };
23}