diff --git a/CHANGELOG.md b/CHANGELOG.md index 15cfc23c..d1c9fac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Version 1.0.0 The official version `1.0`. -Almost the same version as `0.20.3` but with deprecated API removed. +Almost the same version as `0.20.3` but with deprecated API's removed. Breaking changes ---------------- @@ -18,6 +18,7 @@ Enhancements ------------ * New methods `is_odd`, `is_even` for integers, and `is_zero` for all numbers. +* `From` and `From` are added for `Dynamic`, which create object maps with `()` values. Version 0.20.3 diff --git a/src/dynamic.rs b/src/dynamic.rs index 3ae9aae4..81dde6f6 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1977,6 +1977,23 @@ impl, T: Variant + Clone> From> From> for Dynamic { + #[inline(always)] + fn from(value: std::collections::HashSet) -> Self { + Self(Union::Map( + Box::new( + value + .into_iter() + .map(|k| (k.into(), Dynamic::UNIT)) + .collect(), + ), + DEFAULT_TAG_VALUE, + ReadWrite, + )) + } +} +#[cfg(not(feature = "no_object"))] impl, T: Variant + Clone> From> for Dynamic { @@ -1994,6 +2011,22 @@ impl, T: Variant + Clone> From> From> for Dynamic { + #[inline(always)] + fn from(value: std::collections::BTreeSet) -> Self { + Self(Union::Map( + Box::new( + value + .into_iter() + .map(|k| (k.into(), Dynamic::UNIT)) + .collect(), + ), + DEFAULT_TAG_VALUE, + ReadWrite, + )) + } +} impl From for Dynamic { #[inline(always)] fn from(value: FnPtr) -> Self { diff --git a/src/lib.rs b/src/lib.rs index 905e5655..9bd8e204 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,7 +191,7 @@ pub use ast::ScriptFnMetadata; #[cfg(not(feature = "no_index"))] pub type Array = Vec; -/// Hash map of [`Dynamic`] values with [`ImmutableString`] keys. +/// Hash map of [`Dynamic`] values with [`SmartString`](https://crates.io/crates/smartstring) keys. /// Not available under `no_object`. #[cfg(not(feature = "no_object"))] pub type Map = std::collections::BTreeMap;