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 36 37 38 39 40 41 42 43 44 45
use std::any::Any; use std::error::Error; use std::fmt; #[macro_export] macro_rules! view{ () => {Ok($crate::view::ViewResultEnum::CurrentView)}; ($model: expr) => {Ok($crate::view::ViewResultEnum::CurrentViewWithModel(Box::new($model)))}; ($view:expr, $model:expr) => {Ok($crate::view::ViewResultEnum::SpecificViewWithModel(expr.to_string(), Box::new($model)))}; } #[derive(Debug)] pub struct ViewContext { } #[derive(Debug)] pub enum ViewResultEnum { CurrentView, CurrentViewWithModel(Box<Any>), SpecificView(String), SpecificViewWithModel(String, Box<Any>) } pub type ViewResult = Result<ViewResultEnum, ViewError>; #[derive(Debug)] pub enum ViewError { UrlNotFound } impl fmt::Display for ViewError { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { formatter.write_str(self.description()) } } impl Error for ViewError { fn description(&self) -> &str { match *self { ViewError::UrlNotFound => "Url not found" } } }