pub struct Dynamic(/* private fields */);Expand description
Dynamic type containing any value.
Implementations§
Source§impl Dynamic
impl Dynamic
Sourcepub fn as_string(self) -> Result<String, &'static str>
👎Deprecated since 1.1.0: use into_string instead
pub fn as_string(self) -> Result<String, &'static str>
into_string insteadConvert the Dynamic into a String and return it.
If there are other references to the same string, a cloned copy is returned.
Returns the name of the actual type if the cast fails.
§Deprecated
This method is deprecated.
Use into_string instead.
This method will be removed in the next major version.
Sourcepub fn as_immutable_string(self) -> Result<ImmutableString, &'static str>
👎Deprecated since 1.1.0: use into_immutable_string instead
pub fn as_immutable_string(self) -> Result<ImmutableString, &'static str>
into_immutable_string insteadConvert the Dynamic into an ImmutableString and return it.
Returns the name of the actual type if the cast fails.
§Deprecated
This method is deprecated.
Use into_immutable_string instead.
This method will be removed in the next major version.
Source§impl Dynamic
impl Dynamic
Source§impl Dynamic
impl Dynamic
Sourcepub const NEGATIVE_ONE: Dynamic
pub const NEGATIVE_ONE: Dynamic
A Dynamic containing the integer -1.
Sourcepub const NEGATIVE_TWO: Dynamic
pub const NEGATIVE_TWO: Dynamic
A Dynamic containing the integer -2.
Sourcepub const FLOAT_ZERO: Dynamic
pub const FLOAT_ZERO: Dynamic
A Dynamic containing 0.0.
Not available under no_float.
Sourcepub const FLOAT_HUNDRED: Dynamic
pub const FLOAT_HUNDRED: Dynamic
A Dynamic containing 100.0.
Not available under no_float.
Sourcepub const FLOAT_THOUSAND: Dynamic
pub const FLOAT_THOUSAND: Dynamic
A Dynamic containing 1000.0.
Not available under no_float.
Sourcepub const FLOAT_MILLION: Dynamic
pub const FLOAT_MILLION: Dynamic
A Dynamic containing 1000000.0.
Not available under no_float.
Sourcepub const FLOAT_NEGATIVE_ONE: Dynamic
pub const FLOAT_NEGATIVE_ONE: Dynamic
A Dynamic containing -1.0.
Not available under no_float.
Sourcepub const FLOAT_NEGATIVE_TWO: Dynamic
pub const FLOAT_NEGATIVE_TWO: Dynamic
A Dynamic containing -2.0.
Not available under no_float.
Sourcepub const FLOAT_HALF: Dynamic
pub const FLOAT_HALF: Dynamic
A Dynamic containing 0.5.
Not available under no_float.
Sourcepub const FLOAT_QUARTER: Dynamic
pub const FLOAT_QUARTER: Dynamic
A Dynamic containing 0.25.
Not available under no_float.
Sourcepub const FLOAT_FIFTH: Dynamic
pub const FLOAT_FIFTH: Dynamic
A Dynamic containing 0.2.
Not available under no_float.
Sourcepub const FLOAT_TENTH: Dynamic
pub const FLOAT_TENTH: Dynamic
A Dynamic containing 0.1.
Not available under no_float.
Sourcepub const FLOAT_HUNDREDTH: Dynamic
pub const FLOAT_HUNDREDTH: Dynamic
A Dynamic containing 0.01.
Not available under no_float.
Sourcepub const FLOAT_THOUSANDTH: Dynamic
pub const FLOAT_THOUSANDTH: Dynamic
A Dynamic containing 0.001.
Not available under no_float.
Sourcepub const FLOAT_MILLIONTH: Dynamic
pub const FLOAT_MILLIONTH: Dynamic
A Dynamic containing 0.000001.
Not available under no_float.
Sourcepub const FLOAT_HALF_PI: Dynamic
pub const FLOAT_HALF_PI: Dynamic
A Dynamic containing π/2.
Not available under no_float.
Sourcepub const FLOAT_QUARTER_PI: Dynamic
pub const FLOAT_QUARTER_PI: Dynamic
A Dynamic containing π/4.
Not available under no_float.
Sourcepub const FLOAT_TWO_PI: Dynamic
pub const FLOAT_TWO_PI: Dynamic
A Dynamic containing 2π.
Not available under no_float.
Sourcepub const FLOAT_INVERSE_PI: Dynamic
pub const FLOAT_INVERSE_PI: Dynamic
A Dynamic containing 1/π.
Not available under no_float.
Sourcepub const FLOAT_LOG_E: Dynamic
pub const FLOAT_LOG_E: Dynamic
A Dynamic containing log e.
Not available under no_float.
Sourcepub const FLOAT_LN_10: Dynamic
pub const FLOAT_LN_10: Dynamic
A Dynamic containing ln 10.
Not available under no_float.
Sourcepub const fn from_float(value: f64) -> Dynamic
pub const fn from_float(value: f64) -> Dynamic
Sourcepub fn from_map(map: BTreeMap<SmartString<LazyCompact>, Dynamic>) -> Dynamic
pub fn from_map(map: BTreeMap<SmartString<LazyCompact>, Dynamic>) -> Dynamic
Sourcepub fn from_timestamp(value: Instant) -> Dynamic
pub fn from_timestamp(value: Instant) -> Dynamic
Sourcepub fn into_read_only(self) -> Dynamic
pub fn into_read_only(self) -> Dynamic
Make this Dynamic read-only (i.e. a constant).
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Is this Dynamic read-only?
Constant Dynamic values are read-only.
§Usage
If a &mut Dynamic to such a constant is passed to a Rust function, the function
can use this information to return the error
ErrorAssignmentToConstant if its value
will be modified.
This safe-guards constant values from being modified within Rust functions.
§Shared Value
If a Dynamic holds a shared value, then it is read-only only if the shared value
itself is read-only.
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its access mode cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn from<T>(value: T) -> Dynamicwhere
T: Variant + Clone,
pub fn from<T>(value: T) -> Dynamicwhere
T: Variant + Clone,
Create a Dynamic from any type. A Dynamic value is simply returned as is.
§Arrays
Beware that you need to pass in an Array type for it to be recognized as
an Array. A Vec<T> does not get automatically converted to an
Array, but will be a custom type instead (stored as a trait object).
Use array.into() or array.into_iter() to convert a Vec<T> into a Dynamic as
an Array value. See the examples for details.
§Hash Maps
Similarly, passing in a HashMap<String, T> or
BTreeMap<String, T> will not get a Map but a
custom type.
Again, use map.into() to get a Dynamic with a Map value.
See the examples for details.
§Examples
use rhai::Dynamic;
let result = Dynamic::from(42_i64);
assert_eq!(result.type_name(), "i64");
assert_eq!(result.to_string(), "42");
let result = Dynamic::from("hello");
assert_eq!(result.type_name(), "string");
assert_eq!(result.to_string(), "hello");
let new_result = Dynamic::from(result);
assert_eq!(new_result.type_name(), "string");
assert_eq!(new_result.to_string(), "hello");
// Arrays - this is a custom object!
let result = Dynamic::from(vec![1_i64, 2, 3]);
assert_eq!(result.type_name(), "alloc::vec::Vec<i64>");
// Use '.into()' to convert a Vec<T> into an Array
let result: Dynamic = vec![1_i64, 2, 3].into();
assert_eq!(result.type_name(), "array");
// Hash map
let mut map = HashMap::new();
map.insert("a".to_string(), 1_i64);
// This is a custom object!
let result = Dynamic::from(map.clone());
assert_eq!(result.type_name(), "std::collections::hash::map::HashMap<alloc::string::String, i64>");
// Use '.into()' to convert a HashMap<String, T> into an object map
let result: Dynamic = map.into();
assert_eq!(result.type_name(), "map");Turn the Dynamic value into a shared Dynamic value backed by an
Rc<RefCell<Dynamic>> or Arc<RwLock<Dynamic>>
depending on the sync feature.
Not available under no_closure.
Shared Dynamic values are relatively cheap to clone as they simply increment the
reference counts.
Shared Dynamic values can be converted seamlessly to and from ordinary Dynamic
values.
If the Dynamic value is already shared, this method returns itself.
Sourcepub fn take(&mut self) -> Dynamic
pub fn take(&mut self) -> Dynamic
Return this Dynamic, replacing it with Dynamic::UNIT.
Sourcepub fn try_cast<T>(self) -> Option<T>where
T: Any,
pub fn try_cast<T>(self) -> Option<T>where
T: Any,
Convert the Dynamic value into specific type.
Casting to a Dynamic simply returns itself.
§Errors
Returns None if types mismatch.
§Shared Value
If the Dynamic is a shared value, it returns the shared value if there are no
outstanding references, or a cloned copy otherwise.
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
§Example
use rhai::Dynamic;
let x = Dynamic::from(42_u32);
assert_eq!(x.try_cast::<u32>().expect("x should be u32"), 42);Sourcepub fn try_cast_result<T>(self) -> Result<T, Dynamic>where
T: Any,
pub fn try_cast_result<T>(self) -> Result<T, Dynamic>where
T: Any,
Convert the Dynamic value into specific type.
Casting to a Dynamic simply returns itself.
§Errors
Returns itself as an error if types mismatch.
§Shared Value
If the Dynamic is a shared value, it returns the shared value if there are no
outstanding references, or a cloned copy otherwise.
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn cast<T>(self) -> T
pub fn cast<T>(self) -> T
Convert the Dynamic value into a specific type.
Casting to a Dynamic just returns as is.
§Panics
Panics if the cast fails (e.g. the type of the actual value is not the same as the specified type).
§Shared Value
If the Dynamic is a shared value, it returns the shared value if there are no
outstanding references, or a cloned copy otherwise.
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the shared value is simply cloned, which means that the returned value is also shared.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
§Example
use rhai::Dynamic;
let x = Dynamic::from(42_u32);
assert_eq!(x.cast::<u32>(), 42);Sourcepub fn clone_cast<T>(&self) -> T
pub fn clone_cast<T>(&self) -> T
Clone the Dynamic value and convert it into a specific type.
Casting to a Dynamic just returns as is.
§Panics
Panics if the cast fails (e.g. the type of the actual value is not the same as the specified type).
§Shared Value
If the Dynamic is a shared value, a cloned copy of the shared value is returned.
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the shared value is simply cloned.
This normally shouldn’t occur since most operations in Rhai are single-threaded.
§Example
use rhai::Dynamic;
let x = Dynamic::from(42_u32);
let y = &x;
assert_eq!(y.clone_cast::<u32>(), 42);Sourcepub fn flatten_clone(&self) -> Dynamic
pub fn flatten_clone(&self) -> Dynamic
Flatten the Dynamic and clone it.
If the Dynamic is not a shared value, a cloned copy is returned.
If the Dynamic is a shared value, a cloned copy of the shared value is returned.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the shared value is simply cloned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn flatten(self) -> Dynamic
pub fn flatten(self) -> Dynamic
Flatten the Dynamic.
If the Dynamic is not a shared value, it simply returns itself.
If the Dynamic is a shared value, it returns the shared value if there are no
outstanding references, or a cloned copy otherwise.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the shared value is simply cloned, meaning that the result value will also be shared.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn read_lock<T>(&self) -> Option<DynamicReadLock<'_, T>>
pub fn read_lock<T>(&self) -> Option<DynamicReadLock<'_, T>>
Get a reference of a specific type to the Dynamic.
Casting to Dynamic just returns a reference to it.
Returns None if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, this call also fails if the data is currently borrowed for write.
Under these circumstances, None is also returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn write_lock<T>(&mut self) -> Option<DynamicWriteLock<'_, T>>
pub fn write_lock<T>(&mut self) -> Option<DynamicWriteLock<'_, T>>
Get a mutable reference of a specific type to the Dynamic.
Casting to Dynamic just returns a mutable reference to it.
Returns None if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, this call also fails if the data is currently borrowed for write.
Under these circumstances, None is also returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_unit(&self) -> bool
pub fn is_unit(&self) -> bool
Return true if the Dynamic holds a ().
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_int(&self) -> bool
pub fn is_int(&self) -> bool
Return true if the Dynamic holds the system integer type INT.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Return true if the Dynamic holds the system floating-point type FLOAT.
Not available under no_float.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&self) -> bool
Return true if the Dynamic holds a bool.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_char(&self) -> bool
pub fn is_char(&self) -> bool
Return true if the Dynamic holds a char.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Return true if the Dynamic holds an ImmutableString.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Return true if the Dynamic holds an Array.
Not available under no_index.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_blob(&self) -> bool
pub fn is_blob(&self) -> bool
Return true if the Dynamic holds a Blob.
Not available under no_index.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_map(&self) -> bool
pub fn is_map(&self) -> bool
Return true if the Dynamic holds a Map.
Not available under no_object.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_fnptr(&self) -> bool
pub fn is_fnptr(&self) -> bool
Return true if the Dynamic holds a FnPtr.
Note that there is no accompanying as_fnptr() method, use cast() to obtain the FnPtr.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn is_timestamp(&self) -> bool
pub fn is_timestamp(&self) -> bool
Return true if the Dynamic holds a timestamp.
Not available under no_time.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, false is returned.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_unit(&self) -> Result<(), &'static str>
pub fn as_unit(&self) -> Result<(), &'static str>
Cast the Dynamic as a unit ().
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_int(&self) -> Result<i64, &'static str>
pub fn as_int(&self) -> Result<i64, &'static str>
Cast the Dynamic as the system integer type INT.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_float(&self) -> Result<f64, &'static str>
pub fn as_float(&self) -> Result<f64, &'static str>
Cast the Dynamic as the system floating-point type FLOAT.
Not available under no_float.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_bool(&self) -> Result<bool, &'static str>
pub fn as_bool(&self) -> Result<bool, &'static str>
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_char(&self) -> Result<char, &'static str>
pub fn as_char(&self) -> Result<char, &'static str>
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_immutable_string_ref(
&self,
) -> Result<impl Deref<Target = ImmutableString>, &'static str>
pub fn as_immutable_string_ref( &self, ) -> Result<impl Deref<Target = ImmutableString>, &'static str>
Cast the Dynamic as an ImmutableString.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_immutable_string_mut(&mut self) -> Result<impl DerefMut, &'static str>
pub fn as_immutable_string_mut(&mut self) -> Result<impl DerefMut, &'static str>
Cast the Dynamic as a mutable reference to an ImmutableString.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_array_ref(
&self,
) -> Result<impl Deref<Target = Vec<Dynamic>>, &'static str>
pub fn as_array_ref( &self, ) -> Result<impl Deref<Target = Vec<Dynamic>>, &'static str>
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_array_mut(&mut self) -> Result<impl DerefMut, &'static str>
pub fn as_array_mut(&mut self) -> Result<impl DerefMut, &'static str>
Cast the Dynamic as a mutable reference to an Array.
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_blob_ref(&self) -> Result<impl Deref<Target = Vec<u8>>, &'static str>
pub fn as_blob_ref(&self) -> Result<impl Deref<Target = Vec<u8>>, &'static str>
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_blob_mut(&mut self) -> Result<impl DerefMut, &'static str>
pub fn as_blob_mut(&mut self) -> Result<impl DerefMut, &'static str>
Cast the Dynamic as a mutable reference to a Blob.
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_map_ref(
&self,
) -> Result<impl Deref<Target = BTreeMap<SmartString<LazyCompact>, Dynamic>>, &'static str>
pub fn as_map_ref( &self, ) -> Result<impl Deref<Target = BTreeMap<SmartString<LazyCompact>, Dynamic>>, &'static str>
Not available under no_object.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn as_map_mut(&mut self) -> Result<impl DerefMut, &'static str>
pub fn as_map_mut(&mut self) -> Result<impl DerefMut, &'static str>
Cast the Dynamic as a mutable reference to a Map.
Not available under no_object.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn into_string(self) -> Result<String, &'static str>
pub fn into_string(self) -> Result<String, &'static str>
Convert the Dynamic into a String.
If there are other references to the same string, a cloned copy is returned.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn into_immutable_string(self) -> Result<ImmutableString, &'static str>
pub fn into_immutable_string(self) -> Result<ImmutableString, &'static str>
Convert the Dynamic into an ImmutableString.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn into_array(self) -> Result<Vec<Dynamic>, &'static str>
pub fn into_array(self) -> Result<Vec<Dynamic>, &'static str>
Convert the Dynamic into an Array.
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn into_typed_array<T>(self) -> Result<Vec<T>, &'static str>where
T: Variant + Clone,
pub fn into_typed_array<T>(self) -> Result<Vec<T>, &'static str>where
T: Variant + Clone,
Convert the Dynamic into a Vec.
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Sourcepub fn into_blob(self) -> Result<Vec<u8>, &'static str>
pub fn into_blob(self) -> Result<Vec<u8>, &'static str>
Convert the Dynamic into a Blob.
Not available under no_index.
§Errors
Returns the name of the actual type as an error if the cast fails.
§Shared Value
Under the sync feature, a shared value may deadlock.
Otherwise, the data may currently be borrowed for write (so its type cannot be determined).
Under these circumstances, the cast also fails.
These normally shouldn’t occur since most operations in Rhai are single-threaded.
Trait Implementations§
Source§impl<T> From<&[T]> for Dynamicwhere
T: Variant + Clone,
Available on non-crate feature no_index only.
impl<T> From<&[T]> for Dynamicwhere
T: Variant + Clone,
no_index only.Source§impl<K, T> From<HashMap<K, T>> for Dynamic
Available on non-crate feature no_object and non-crate feature no_std only.
impl<K, T> From<HashMap<K, T>> for Dynamic
no_object and non-crate feature no_std only.Source§impl<K> From<HashSet<K>> for Dynamic
Available on non-crate feature no_object and non-crate feature no_std only.
impl<K> From<HashSet<K>> for Dynamic
no_object and non-crate feature no_std only.Source§impl<T> From<Vec<T>> for Dynamicwhere
T: Variant + Clone,
Available on non-crate feature no_index only.
impl<T> From<Vec<T>> for Dynamicwhere
T: Variant + Clone,
no_index only.Source§impl<T> FromIterator<T> for Dynamicwhere
T: Variant + Clone,
Available on non-crate feature no_index only.
impl<T> FromIterator<T> for Dynamicwhere
T: Variant + Clone,
no_index only.