diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd9bb72..323a7cc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ New features * Each `Dynamic` value can now contain arbitrary data (type `i16`) in the form of a _tag_. This is to use up otherwise wasted space in the `Dynamic` type. * A new internal feature `no_smartstring` to turn off `SmartString` for those rare cases that it is needed. * `DynamicReadLock` and `DynamicWriteLoc` are exposed under `internals`. +* `From>>` is added for `Dynamic` mapping directly to a shared value, together with support for `Dynamic::from`. Enhancements ------------ diff --git a/src/dynamic.rs b/src/dynamic.rs index 5b1a01d5..f56bf4b0 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1027,35 +1027,43 @@ impl Dynamic { } value = match unsafe_try_cast::<_, String>(value) { - Ok(s) => return (s).into(), - Err(val) => val, + Ok(s) => return s.into(), + Err(value) => value, }; #[cfg(not(feature = "no_index"))] { value = match unsafe_try_cast::<_, Array>(value) { - Ok(array) => return (array).into(), - Err(val) => val, + Ok(array) => return array.into(), + Err(value) => value, }; } #[cfg(not(feature = "no_object"))] { value = match unsafe_try_cast::<_, Map>(value) { - Ok(map) => return (map).into(), - Err(val) => val, + Ok(map) => return map.into(), + Err(value) => value, }; } value = match unsafe_try_cast::<_, FnPtr>(value) { - Ok(fn_ptr) => return (fn_ptr).into(), - Err(val) => val, + Ok(fn_ptr) => return fn_ptr.into(), + Err(value) => value, }; #[cfg(not(feature = "no_std"))] { value = match unsafe_try_cast::<_, Instant>(value) { - Ok(timestamp) => return (timestamp).into(), - Err(val) => val, + Ok(timestamp) => return timestamp.into(), + Err(value) => value, + }; + } + + #[cfg(not(feature = "no_closure"))] + { + value = match unsafe_try_cast::<_, crate::Shared>>(value) { + Ok(value) => return value.into(), + Err(value) => value, }; } @@ -1974,3 +1982,14 @@ impl From for Dynamic { )) } } +#[cfg(not(feature = "no_closure"))] +impl From>> for Dynamic { + #[inline(always)] + fn from(value: crate::Shared>) -> Self { + Self(Union::Shared( + value.into(), + DEFAULT_TAG, + AccessMode::ReadWrite, + )) + } +}