[−][src]Struct rhai::Dynamic
Dynamic type containing any value.
Implementations
impl Dynamic
[src]
pub fn is_variant(&self) -> bool
[src]
Does this Dynamic
hold a variant data type
instead of one of the support system primitive types?
pub fn is<T: Variant + Clone>(&self) -> bool
[src]
Is the value held by this Dynamic
a particular type?
pub fn type_id(&self) -> TypeId
[src]
Get the TypeId of the value held by this Dynamic
.
pub fn type_name(&self) -> &'static str
[src]
Get the name of the type of the value held by this Dynamic
.
impl Dynamic
[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>
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".to_string()); 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 try_cast<T: Variant>(self) -> Option<T>
[src]
Get a copy of the Dynamic
value as a specific type.
Casting to a Dynamic
just returns as is.
Returns an error with the name of the value's actual type when the cast fails.
Example
use rhai::Dynamic; let x = Dynamic::from(42_u32); assert_eq!(x.try_cast::<u32>().unwrap(), 42);
pub fn cast<T: Variant + Clone>(self) -> T
[src]
Get a copy of the Dynamic
value as 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).
Example
use rhai::Dynamic; let x = Dynamic::from(42_u32); assert_eq!(x.cast::<u32>(), 42);
pub fn downcast_ref<T: Variant + Clone>(&self) -> Option<&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.
pub fn downcast_mut<T: Variant + Clone>(&mut self) -> Option<&mut 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.
pub fn as_int(&self) -> Result<INT, &'static str>
[src]
Cast the Dynamic
as the system integer type INT
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_float(&self) -> Result<FLOAT, &'static str>
[src]
Cast the Dynamic
as the system floating-point type FLOAT
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_bool(&self) -> Result<bool, &'static str>
[src]
Cast the Dynamic
as a bool
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_char(&self) -> Result<char, &'static str>
[src]
Cast the Dynamic
as a char
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_str(&self) -> Result<&str, &'static str>
[src]
Cast the Dynamic
as a string and return the string slice.
Returns the name of the actual type if the cast fails.
pub fn take_string(self) -> Result<String, &'static str>
[src]
Convert the Dynamic
into String
and return it.
Returns the name of the actual type if the cast fails.
Trait Implementations
impl Clone for Dynamic
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Dynamic
[src]
impl Default for Dynamic
[src]
impl Display for Dynamic
[src]
impl<'_, T: Variant + Clone> From<&'_ [T]> for Dynamic
[src]
impl From<()> for Dynamic
[src]
impl<T: Variant + Clone> From<HashMap<String, T, RandomState>> for Dynamic
[src]
impl From<ImmutableString> for Dynamic
[src]
fn from(value: ImmutableString) -> Self
[src]
impl From<String> for Dynamic
[src]
impl<T: Variant + Clone> From<Vec<T>> for Dynamic
[src]
impl From<bool> for Dynamic
[src]
impl From<char> for Dynamic
[src]
impl From<f64> for Dynamic
[src]
impl From<i64> for Dynamic
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,