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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use crate::result::{Error, Result}; use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] pub enum Theme { Light, Dark } impl std::str::FromStr for Theme { type Err = Error; fn from_str(s: &str) -> Result<Self> { match s { "Light" => Ok(Theme::Light), "Dark" => Ok(Theme::Dark), _ => Err(Error::from(format!("Invalid theme [{}]", s))) } } } impl Theme { pub fn default_navbar_color(&self) -> String { match self { Theme::Light => "#263238".into(), Theme::Dark => "#263238".into() } } pub fn body_class(&self) -> &str { match self { Theme::Light => "uk-dark", Theme::Dark => "uk-light" } } } #[derive(Debug, Deserialize, Serialize)] pub struct UserProfile { name: String, theme: Theme, nav_color: String } impl UserProfile { pub fn new(name: String, theme: Theme, nav_color: String) -> UserProfile { UserProfile { name, theme, nav_color } } pub fn name(&self) -> &String { &self.name } pub fn theme(&self) -> &Theme { &self.theme } pub fn nav_color(&self) -> &String { &self.nav_color } }