diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-01-13 14:36:40 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-01-13 14:36:40 +0100 |
| commit | dde69276d47818174c35523c8ed86b6888b6d02b (patch) | |
| tree | 68f0f56efd42f47156fddf67158cdcdcde3717b9 /src/library/maps/mod.rs | |
| parent | 6527d31dfba78330a39e52d7772f6c8561fb23ef (diff) | |
Refactor expressions and create tuples and objects 🧮
Diffstat (limited to 'src/library/maps/mod.rs')
| -rw-r--r-- | src/library/maps/mod.rs | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/library/maps/mod.rs b/src/library/maps/mod.rs index 5e130d53..a868ce6c 100644 --- a/src/library/maps/mod.rs +++ b/src/library/maps/mod.rs @@ -36,6 +36,37 @@ pub_use_mod!(axis); pub_use_mod!(alignment); pub_use_mod!(padding); + +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum DefaultKey<T> { + Some(T), + None, +} + +impl<T> Into<Option<T>> for DefaultKey<T> { + fn into(self) -> Option<T> { + match self { + DefaultKey::Some(v) => Some(v), + DefaultKey::None => None, + } + } +} + +impl<T> ExpressionKind for DefaultKey<T> where T: ExpressionKind { + const NAME: &'static str = T::NAME; + + fn from_expr(expr: Spanned<Expression>) -> ParseResult<DefaultKey<T>> { + if let Expression::Ident(ident) = &expr.v { + match ident.as_str() { + "default" => return Ok(DefaultKey::None), + _ => {}, + } + } + + T::from_expr(expr).map(|v| DefaultKey::Some(v)) + } +} + /// A deduplicating map type useful for storing possibly redundant arguments. #[derive(Debug, Clone, PartialEq)] pub struct ConsistentMap<K, V> where K: Hash + Eq { @@ -95,10 +126,3 @@ impl<K, V> ConsistentMap<K, V> where K: Hash + Eq { self.map.iter() } } - -key!(Direction, "direction", - "left-to-right" | "ltr" => LeftToRight, - "right-to-left" | "rtl" => RightToLeft, - "top-to-bottom" | "ttb" => TopToBottom, - "bottom-to-top" | "btt" => BottomToTop, -); |
