diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-06-13 23:16:40 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-06-14 13:53:02 +0200 |
| commit | c81e2a5f56eb262663f292578c683fba7f18251f (patch) | |
| tree | 6c045a8dcbec5e75e01a15f970ef8cee6ff042d0 /src/eval/dict.rs | |
| parent | 891af17260a6750a74a102388a05e59cf1ffc3c1 (diff) | |
Many fixes
Diffstat (limited to 'src/eval/dict.rs')
| -rw-r--r-- | src/eval/dict.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/eval/dict.rs b/src/eval/dict.rs index 35bd75d5..8893ce48 100644 --- a/src/eval/dict.rs +++ b/src/eval/dict.rs @@ -46,7 +46,7 @@ impl Dict { } /// Borrow the value the given `key` maps to. - pub fn get(&self, key: &EcoString) -> StrResult<&Value> { + pub fn get(&self, key: &str) -> StrResult<&Value> { self.0.get(key).ok_or_else(|| missing_key(key)) } @@ -59,7 +59,7 @@ impl Dict { } /// Whether the dictionary contains a specific key. - pub fn contains(&self, key: &EcoString) -> bool { + pub fn contains(&self, key: &str) -> bool { self.0.contains_key(key) } @@ -69,7 +69,7 @@ impl Dict { } /// Remove a mapping by `key`. - pub fn remove(&mut self, key: &EcoString) -> StrResult<()> { + pub fn remove(&mut self, key: &str) -> StrResult<()> { match Arc::make_mut(&mut self.0).remove(key) { Some(_) => Ok(()), None => Err(missing_key(key)), @@ -87,12 +87,12 @@ impl Dict { /// Return the keys of the dictionary as an array. pub fn keys(&self) -> Array { - self.iter().map(|(key, _)| Value::Str(key.clone())).collect() + self.0.keys().cloned().map(Value::Str).collect() } /// Return the values of the dictionary as an array. pub fn values(&self) -> Array { - self.iter().map(|(_, value)| value.clone()).collect() + self.0.values().cloned().collect() } /// Transform each pair in the array with a function. @@ -114,8 +114,8 @@ impl Dict { /// The missing key access error message. #[cold] -fn missing_key(key: &EcoString) -> String { - format!("dictionary does not contain key {:?}", key) +fn missing_key(key: &str) -> String { + format!("dictionary does not contain key {:?}", EcoString::from(key)) } impl Debug for Dict { |
