1use serde_json::Value;
2
3pub struct ViewResponse {
4 pub template: String,
5 pub context: Value,
6 pub status: u16,
7 pub layout: Option<String>,
8}
9
10impl ViewResponse {
11 pub fn new(template: impl Into<String>, context: Value) -> Self {
12 Self {
13 template: template.into(),
14 context,
15 status: 200,
16 layout: None,
17 }
18 }
19
20 pub fn status(mut self, code: u16) -> Self {
21 self.status = code;
22 self
23 }
24
25 pub fn layout(mut self, name: impl Into<String>) -> Self {
26 self.layout = Some(name.into());
27 self
28 }
29
30 pub fn no_layout(mut self) -> Self {
31 self.layout = Some(String::new());
32 self
33 }
34}