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 63 64 65 66 67 68
#[macro_use] extern crate serde_derive; use std::path::{Path, PathBuf}; #[derive(Debug, Serialize)] pub struct Item { title: String, #[serde(skip_serializing_if = "Option::is_none")] subtitle: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] arg: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] icon: Option<Icon>, #[serde(skip_serializing_if = "Option::is_none")] valid: Option<bool>, } impl Item { pub fn new<S: Into<String>>(title: S) -> Self { Item { title: title.into(), subtitle: None, arg: None, icon: None, valid: None, } } pub fn subtitle(mut self, subtitle: &str) -> Self { self.subtitle = Some(subtitle.into()); self } pub fn arg(mut self, arg: &str) -> Self { self.arg = Some(arg.into()); self } pub fn icon<I: Into<Icon>>(mut self, icon: I) -> Self { self.icon = Some(icon.into()); self } pub fn valid(mut self, valid: bool) -> Self { self.valid = Some(valid); self } } #[derive(Debug, Serialize)] pub struct Icon { pub path: PathBuf, } impl<'a> From<&'a str> for Icon { fn from(s: &str) -> Self { let path = s.into(); Self { path } } } impl<'a> From<&'a Path> for Icon { fn from(p: &Path) -> Self { let path = p.into(); Self { path } } }