diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-06-06 21:13:59 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-06-06 22:06:16 +0200 |
| commit | fd417da04f7ca4b995de7f6510abafd3e9c31307 (patch) | |
| tree | 3675529c75ca7363701ac8ea306de2cc1d3cbcb3 /src/eval/dict.rs | |
| parent | 168bdf35bd773e67343c965cb473492cc5cae9e7 (diff) | |
Improve value casting infrastructure
Diffstat (limited to 'src/eval/dict.rs')
| -rw-r--r-- | src/eval/dict.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/eval/dict.rs b/src/eval/dict.rs index 49a60147..3e6233ae 100644 --- a/src/eval/dict.rs +++ b/src/eval/dict.rs @@ -17,8 +17,8 @@ macro_rules! __dict { ($($key:expr => $value:expr),* $(,)?) => {{ #[allow(unused_mut)] let mut map = $crate::eval::IndexMap::new(); - $(map.insert($key.into(), $value.into());)* - $crate::eval::Dict::from_map(map) + $(map.insert($key.into(), $crate::eval::IntoValue::into_value($value));)* + $crate::eval::Dict::from(map) }}; } @@ -38,19 +38,14 @@ impl Dict { Self::default() } - /// Create a new dictionary from a mapping of strings to values. - pub fn from_map(map: IndexMap<Str, Value>) -> Self { - Self(Arc::new(map)) - } - /// Whether the dictionary is empty. pub fn is_empty(&self) -> bool { self.0.is_empty() } /// The number of pairs in the dictionary. - pub fn len(&self) -> i64 { - self.0.len() as i64 + pub fn len(&self) -> usize { + self.0.len() } /// Borrow the value the given `key` maps to, @@ -217,6 +212,12 @@ impl<'a> IntoIterator for &'a Dict { } } +impl From<IndexMap<Str, Value>> for Dict { + fn from(map: IndexMap<Str, Value>) -> Self { + Self(Arc::new(map)) + } +} + /// The missing key access error message. #[cold] fn missing_key(key: &str) -> EcoString { |
