summaryrefslogtreecommitdiff
path: root/src/library/maps/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-13 14:36:40 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-13 14:36:40 +0100
commitdde69276d47818174c35523c8ed86b6888b6d02b (patch)
tree68f0f56efd42f47156fddf67158cdcdcde3717b9 /src/library/maps/mod.rs
parent6527d31dfba78330a39e52d7772f6c8561fb23ef (diff)
Refactor expressions and create tuples and objects 🧮
Diffstat (limited to 'src/library/maps/mod.rs')
-rw-r--r--src/library/maps/mod.rs38
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,
-);