瀏覽代碼

Implements the majority of HashMap methods

Map should now except for most of HashMap's methods being prefixed,
should be ready for use. (I also fixed a missing vec prefix for
vec_get_mut)
Steve Thielemann 2 月之前
父節點
當前提交
42e4dc457a
共有 1 個文件被更改,包括 35 次插入1 次删除
  1. 35 1
      src/data.rs

+ 35 - 1
src/data.rs

@@ -716,7 +716,7 @@ impl Data {
         }
     }
     /// Gets like [Data::vec_get] except as mutable 
-    pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
+    pub fn vec_get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
     where
         I: SliceIndex<[Data]>,
     {
@@ -725,6 +725,40 @@ impl Data {
             _ => None,
         }
     }
+    pub fn map_contains_key(&self, key: &String) -> bool {
+        match self {
+            Self::Map(hm) => hm.contains_key(key),
+            _ => false,
+        }
+    }
+    /// Get for a Map, see [HashMap::get]
+    pub fn map_get(&self, key: &String) -> Option<&Data> {
+        match self {
+            Self::Map(hm) => hm.get(key),
+            _ => None
+        }
+    }
+    /// Get as mutable for a Map
+    pub fn map_get_mut(&mut self, key: &String) -> Option<&mut Data> {
+        match self {
+            Self::Map(hm) => hm.get_mut(key),
+            _ => None
+        }
+    }
+    /// Get Key & Value for a Map
+    pub fn map_get_key_value(&self, key: &String) -> Option<(&String, &Data)> {
+        match self {
+            Self::Map(hm) => hm.get_key_value(key),
+            _ => None
+        }
+    }
+    /// Removes for a Map
+    pub fn map_remove(&mut self, key: &String) -> Option<Data> {
+        match self {
+            Self::Map(hm) => hm.remove(key),
+            _ => None
+        }
+    }
     /// Swaps a with b in a Vec
     pub fn vec_swap(&mut self, a: usize, b: usize) {
         if let Self::Vec(v) = self { v.swap(a, b) }