Struct rhai::Dynamic [−][src]
pub struct Dynamic(_);
Expand description
Dynamic type containing any value.
Implementations
impl Dynamic
[src]
impl Dynamic
[src]pub const fn is_variant(&self) -> bool
[src]
pub const fn is_variant(&self) -> bool
[src]Does this Dynamic
hold a variant data type
instead of one of the supported system primitive types?
pub const fn is_shared(&self) -> bool
[src]
pub const fn is_shared(&self) -> bool
[src]Is the value held by this Dynamic
shared?
Not available under no_closure
.
impl Dynamic
[src]
impl Dynamic
[src]pub const NEGATIVE_ONE: Dynamic
[src]
pub const NEGATIVE_ONE: Dynamic
[src]A Dynamic
containing the integer negative one.
pub const FLOAT_ZERO: Dynamic
[src]
pub const FLOAT_ZERO: Dynamic
[src]A Dynamic
containing 0.0
.
Not available under no_float
.
pub const FLOAT_NEGATIVE_ONE: Dynamic
[src]
pub const FLOAT_NEGATIVE_ONE: Dynamic
[src]A Dynamic
containing the -1.0
.
Not available under no_float
.
pub fn is_read_only(&self) -> bool
[src]
pub fn is_read_only(&self) -> bool
[src]Is this Dynamic
read-only?
Constant Dynamic
values are read-only. If a &mut Dynamic
to such a constant
is passed to a Rust function, the function can use this information to return an error of
ErrorAssignmentToConstant
if its value is going to be modified. This safe-guards constant values from being modified
from within Rust functions.
pub fn from<T: Variant + Clone>(value: T) -> Self
[src]
pub fn from<T: Variant + Clone>(value: T) -> Self
[src]Create a Dynamic
from any type. A Dynamic
value is simply returned as is.
Safety
This type uses some unsafe code, mainly for type casting.
Notes
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 generic
restricted trait object instead, because Vec<T>
is not a supported standard type.
Similarly, passing in a HashMap<String, T>
or
BTreeMap<String, T>
will not get a Map
but a trait object.
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");
pub fn into_shared(self) -> Self
[src]
pub fn into_shared(self) -> Self
[src]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.
pub fn try_cast<T: Any>(self) -> Option<T>
[src]
pub fn try_cast<T: Any>(self) -> Option<T>
[src]Convert the Dynamic
value into specific type.
Casting to a Dynamic
just returns as is, but if it contains a shared value,
it is cloned into a Dynamic
with a normal value.
Returns None
if types mismatched.
Panics or Deadlocks
Under the sync
feature, this call may deadlock, or panic.
Otherwise, this call panics if the data is currently borrowed for write.
These normally shouldn’t occur since most operations in Rhai is single-threaded.
Example
use rhai::Dynamic; let x = Dynamic::from(42_u32); assert_eq!(x.try_cast::<u32>().unwrap(), 42);
pub fn cast<T: Any + Clone>(self) -> T
[src]
pub fn cast<T: Any + Clone>(self) -> T
[src]Convert the Dynamic
value into a specific type.
Casting to a Dynamic
just returns as is, but if it contains a shared value,
it is cloned into a Dynamic
with a normal value.
Returns None
if types mismatched.
Panics or Deadlocks
Panics if the cast fails (e.g. the type of the actual value is not the same as the specified type).
Under the sync
feature, this call may deadlock, or panic.
Otherwise, this call panics if the data is currently borrowed for write.
These normally shouldn’t occur since most operations in Rhai is single-threaded.
Example
use rhai::Dynamic; let x = Dynamic::from(42_u32); assert_eq!(x.cast::<u32>(), 42);
pub fn clone_cast<T: Any + Clone>(&self) -> T
[src]
pub fn clone_cast<T: Any + Clone>(&self) -> T
[src]Clone the Dynamic
value and convert it into a specific type.
Casting to a Dynamic
just returns as is, but if it contains a shared value,
it is cloned into a Dynamic
with a normal value.
Returns None
if types mismatched.
Panics or Deadlocks
Panics if the cast fails (e.g. the type of the actual value is not the same as the specified type).
Under the sync
feature, this call may deadlock, or panic.
Otherwise, this call panics if the data is currently borrowed for write.
These normally shouldn’t occur since most operations in Rhai is single-threaded.
Example
use rhai::Dynamic; let x = Dynamic::from(42_u32); let y = &x; assert_eq!(y.clone_cast::<u32>(), 42);
pub fn flatten_clone(&self) -> Self
[src]
pub fn flatten_clone(&self) -> Self
[src]pub fn read_lock<T: Any + Clone>(&self) -> Option<DynamicReadLock<'_, T>>
[src]
pub fn read_lock<T: Any + Clone>(&self) -> Option<DynamicReadLock<'_, T>>
[src]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.
Panics or Deadlocks When Value is Shared
Under the sync
feature, this call may deadlock, or panic.
Otherwise, this call panics if the data is currently borrowed for write.
pub fn write_lock<T: Any + Clone>(&mut self) -> Option<DynamicWriteLock<'_, T>>
[src]
pub fn write_lock<T: Any + Clone>(&mut self) -> Option<DynamicWriteLock<'_, T>>
[src]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.
Panics or Deadlocks When Value is Shared
Under the sync
feature, this call may deadlock, or panic.
Otherwise, this call panics if the data is currently borrowed for write.
pub fn as_unit(&self) -> Result<(), &'static str>
[src]
pub fn as_unit(&self) -> Result<(), &'static str>
[src]Cast the Dynamic
as a unit ()
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_decimal(&self) -> Result<Decimal, &'static str>
[src]
pub fn as_decimal(&self) -> Result<Decimal, &'static str>
[src]pub fn take_string(self) -> Result<String, &'static str>
[src]
pub fn take_string(self) -> Result<String, &'static str>
[src]pub fn take_immutable_string(self) -> Result<ImmutableString, &'static str>
[src]
pub fn take_immutable_string(self) -> Result<ImmutableString, &'static str>
[src]Convert the Dynamic
into an ImmutableString
and return it.
Returns the name of the actual type if the cast fails.
Trait Implementations
impl<'d> Deserialize<'d> for Dynamic
[src]
impl<'d> Deserialize<'d> for Dynamic
[src]fn deserialize<D: Deserializer<'d>>(de: D) -> Result<Self, D::Error>
[src]
fn deserialize<D: Deserializer<'d>>(de: D) -> Result<Self, D::Error>
[src]Deserialize this value from the given Serde deserializer. Read more
impl From<&'_ ImmutableString> for Dynamic
[src]
impl From<&'_ ImmutableString> for Dynamic
[src]fn from(value: &ImmutableString) -> Self
[src]
fn from(value: &ImmutableString) -> Self
[src]Performs the conversion.
impl From<&'_ SmartString<Compact>> for Dynamic
[src]
impl From<&'_ SmartString<Compact>> for Dynamic
[src]fn from(value: &Identifier) -> Self
[src]
fn from(value: &Identifier) -> Self
[src]Performs the conversion.
impl From<FloatWrapper<f64>> for Dynamic
[src]
impl From<FloatWrapper<f64>> for Dynamic
[src]fn from(value: FloatWrapper<FLOAT>) -> Self
[src]
fn from(value: FloatWrapper<FLOAT>) -> Self
[src]Performs the conversion.
impl<K: Into<Identifier>, T: Variant + Clone> From<HashMap<K, T, RandomState>> for Dynamic
[src]
impl<K: Into<Identifier>, T: Variant + Clone> From<HashMap<K, T, RandomState>> for Dynamic
[src]impl<S: Into<ImmutableString>> From<S> for Dynamic
[src]
impl<S: Into<ImmutableString>> From<S> for Dynamic
[src]impl<T: Variant + Clone> FromIterator<T> for Dynamic
[src]
impl<T: Variant + Clone> FromIterator<T> for Dynamic
[src]fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self
[src]
fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self
[src]Creates a value from an iterator. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Dynamic
impl !Send for Dynamic
impl !Sync for Dynamic
impl Unpin for Dynamic
impl !UnwindSafe for Dynamic
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> CallHasher for T where
T: Hash + ?Sized,
[src]
impl<T> CallHasher for T where
T: Hash + ?Sized,
[src]impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,