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
use either::Either; pub fn use_str<V: AsRef<str>>(val: V) -> Vec<String> { vec![val.as_ref().to_owned()] } pub fn use_key<K: AsRef<str>>(val: bool, key: K) -> Vec<String> { if val { vec![key.as_ref().to_owned()] } else { vec![] } } pub fn use_option<V: AsRef<str>>(val: &Option<V>) -> Vec<String> { if val.is_some() { vec![val.as_ref().unwrap().as_ref().to_owned()] } else { vec![] } } pub fn use_option_and_key<V: AsRef<str>, K: AsRef<str>>(val: &Option<V>, key: K) -> Vec<String> { if val.is_some() { vec![val.as_ref().unwrap().as_ref().to_owned(), key.as_ref().to_owned()] } else { vec![] } } pub fn use_key_or_option_and_key<V: AsRef<str>, K: AsRef<str>>(val: &Either<bool, V>, key: K) -> Vec<String> { match val { Either::Left(b) => { if *b { vec![key.as_ref().to_owned()] } else { vec![] } }, Either::Right(v) => { vec![v.as_ref().to_owned(), key.as_ref().to_owned()] } } } pub fn use_text_align<V: AsRef<str>>(val: V) -> Vec<String> { if val.as_ref() == "justified" { vec!["justified".to_string()] } else { use_option_and_key(&Some(val), "aligned") } } #[macro_export] macro_rules! cx { () => { vec![] }; ($($e:expr), *) => { { let mut __gnerated_classes = vec![]; $( __gnerated_classes.append(&mut $e); )* __gnerated_classes } } }