summaryrefslogtreecommitdiff
path: root/src/func
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-06 13:26:44 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-06 13:26:44 +0100
commit1099330988da78c82c6e155fab88d81fb2f1d4c0 (patch)
tree5a13332defa0ad482ed8669ad52f59a595aa25d6 /src/func
parentf5b104d0da1c414fb59878d7378add316ee14798 (diff)
Finish consistent map and add two further convenience maps 🗺
Diffstat (limited to 'src/func')
-rw-r--r--src/func/macros.rs2
-rw-r--r--src/func/map.rs59
-rw-r--r--src/func/mod.rs4
3 files changed, 1 insertions, 64 deletions
diff --git a/src/func/macros.rs b/src/func/macros.rs
index daae2769..17a554cf 100644
--- a/src/func/macros.rs
+++ b/src/func/macros.rs
@@ -29,7 +29,7 @@ macro_rules! function {
function!(@parse $type $meta | $($rest)*);
};
- // Set the metadata to `()` if there is not type definition.
+ // Set the metadata to `()` if there is no type definition.
(@meta $type:ident | $($rest:tt)*) => {
function!(@parse $type () | $($rest)*);
};
diff --git a/src/func/map.rs b/src/func/map.rs
deleted file mode 100644
index 880fe3e6..00000000
--- a/src/func/map.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-//! A deduplicating map.
-
-use std::collections::HashMap;
-use std::hash::Hash;
-
-use crate::syntax::{Spanned, ParseResult};
-
-/// A deduplicating map type useful for storing possibly redundant arguments.
-#[derive(Debug, Clone, PartialEq)]
-pub struct ConsistentMap<K, V> where K: Hash + Eq {
- map: HashMap<K, V>,
-}
-
-impl<K, V> ConsistentMap<K, V> where K: Hash + Eq {
- pub fn new() -> ConsistentMap<K, V> {
- ConsistentMap { map: HashMap::new() }
- }
-
- /// Add a key-value pair.
- pub fn add(&mut self, key: K, value: V) -> ParseResult<()> {
- self.map.insert(key, value);
- // TODO
- Ok(())
- }
-
- /// Add a key-value pair if the value is not `None`.
- pub fn add_opt(&mut self, key: K, value: Option<V>) -> ParseResult<()> {
- Ok(if let Some(value) = value {
- self.add(key, value)?;
- })
- }
-
- /// Add a key-spanned-value pair the value is not `None`.
- pub fn add_opt_span(&mut self, key: K, value: Option<Spanned<V>>) -> ParseResult<()> {
- Ok(if let Some(spanned) = value {
- self.add(key, spanned.v)?;
- })
- }
-
- /// Call a function with the value if the key is present.
- pub fn with<F>(&self, key: K, callback: F) where F: FnOnce(&V) {
- if let Some(value) = self.map.get(&key) {
- callback(value);
- }
- }
-
- /// Create a new consistent map where keys and values are mapped to new
- /// keys and values. Returns an error if a new key is duplicate.
- pub fn dedup<F, K2, V2>(&self, _f: F) -> ParseResult<ConsistentMap<K2, V2>>
- where F: FnOnce(K, V) -> ParseResult<(K2, V2)>, K2: Hash + Eq {
- // TODO
- Ok(ConsistentMap::new())
- }
-
- /// Iterate over the (key, value) pairs.
- pub fn iter(&self) -> std::collections::hash_map::Iter<'_, K, V> {
- self.map.iter()
- }
-}
diff --git a/src/func/mod.rs b/src/func/mod.rs
index dd2a0ca9..53cfece0 100644
--- a/src/func/mod.rs
+++ b/src/func/mod.rs
@@ -8,13 +8,9 @@ use self::prelude::*;
#[macro_use]
mod macros;
-mod map;
-
-pub use map::ConsistentMap;
/// Useful imports for creating your own functions.
pub mod prelude {
- pub use super::map::ConsistentMap;
pub use crate::func::{Scope, ParseFunc, LayoutFunc, Command, Commands};
pub use crate::layout::{
layout_tree, Layout, MultiLayout,