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
use std::collections::HashMap; use response::Response; pub trait Context { fn get_response(&self) -> Response; fn set_body(&mut self, String); } pub struct BasicContext { pub body: String, pub params: HashMap<String, String> } impl BasicContext { pub fn new() -> BasicContext { BasicContext { body: "".to_owned(), params: HashMap::new() } } } impl Context for BasicContext { fn get_response(&self) -> Response { let mut response = Response::new(); response.body(&self.body); response } fn set_body(&mut self, body: String) { self.body = body; } }