Add From<BTreeSet> and From<HashSet> for Dynamic.
This commit is contained in:
parent
fc0256aff9
commit
f033896fec
@ -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<BTreeSet>` and `From<HashSet>` are added for `Dynamic`, which create object maps with `()` values.
|
||||
|
||||
|
||||
Version 0.20.3
|
||||
|
@ -1977,6 +1977,23 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::Hash
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
impl<K: Into<crate::Identifier>> From<std::collections::HashSet<K>> for Dynamic {
|
||||
#[inline(always)]
|
||||
fn from(value: std::collections::HashSet<K>) -> 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<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::BTreeMap<K, T>>
|
||||
for Dynamic
|
||||
{
|
||||
@ -1994,6 +2011,22 @@ impl<K: Into<crate::Identifier>, T: Variant + Clone> From<std::collections::BTre
|
||||
))
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
impl<K: Into<crate::Identifier>> From<std::collections::BTreeSet<K>> for Dynamic {
|
||||
#[inline(always)]
|
||||
fn from(value: std::collections::BTreeSet<K>) -> Self {
|
||||
Self(Union::Map(
|
||||
Box::new(
|
||||
value
|
||||
.into_iter()
|
||||
.map(|k| (k.into(), Dynamic::UNIT))
|
||||
.collect(),
|
||||
),
|
||||
DEFAULT_TAG_VALUE,
|
||||
ReadWrite,
|
||||
))
|
||||
}
|
||||
}
|
||||
impl From<FnPtr> for Dynamic {
|
||||
#[inline(always)]
|
||||
fn from(value: FnPtr) -> Self {
|
||||
|
@ -191,7 +191,7 @@ pub use ast::ScriptFnMetadata;
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
pub type Array = Vec<Dynamic>;
|
||||
|
||||
/// 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<Identifier, Dynamic>;
|
||||
|
Loading…
Reference in New Issue
Block a user