Add From<BTreeSet> and From<HashSet> for Dynamic.
This commit is contained in:
@@ -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>;
|
||||
|
Reference in New Issue
Block a user