Struct casbin::rhai::Dynamic [−][src]
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 supported system primitive types?
pub fn is_shared(&self) -> bool
[src]
pub fn is<T>(&self) -> bool where
T: Variant + Clone,
[src]
T: Variant + Clone,
Is the value held by this Dynamic
a particular type?
If the Dynamic
is a shared variant checking is performed on
top of its internal value.
pub fn type_id(&self) -> TypeId
[src]
Get the TypeId
of the value held by this Dynamic
.
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 type_name(&self) -> &'static str
[src]
Get the name of the type of the value held by this Dynamic
.
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.
impl Dynamic
[src]
pub const UNIT: Dynamic
[src]
A Dynamic
containing a ()
.
pub const TRUE: Dynamic
[src]
A Dynamic
containing a true
.
pub const FALSE: Dynamic
[src]
pub const ZERO: Dynamic
[src]
A Dynamic
containing the integer zero.
pub const ONE: Dynamic
[src]
A Dynamic
containing the integer one.
pub const NEGATIVE_ONE: Dynamic
[src]
A Dynamic
containing the integer negative one.
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>(value: T) -> Dynamic where
T: Variant + Clone,
[src]
T: Variant + Clone,
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 try_cast<T>(self) -> Option<T> where
T: Variant,
[src]
T: Variant,
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>(self) -> T where
T: Variant + Clone,
[src]
T: Variant + Clone,
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>(&self) -> T where
T: Variant + Clone,
[src]
T: Variant + Clone,
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) -> Dynamic
[src]
Flatten the Dynamic
and clone it.
If the Dynamic
is not a shared value, it returns a cloned copy.
If the Dynamic
is a shared value, it a cloned copy of the shared value.
pub fn flatten(self) -> Dynamic
[src]
Flatten the Dynamic
.
If the Dynamic
is not a shared value, it returns itself.
If the Dynamic
is a shared value, it returns the shared value if there are no
outstanding references, or a cloned copy.
pub fn is_locked(&self) -> bool
[src]
Is the Dynamic
a shared value that is locked?
Note
Under the sync
feature, shared values use RwLock
and they are never locked.
Access just waits until the RwLock
is released.
So this method always returns false
under Sync
.
pub fn read_lock<T>(&self) -> Option<DynamicReadLock<'_, T>> where
T: Variant + Clone,
[src]
T: Variant + Clone,
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>(&mut self) -> Option<DynamicWriteLock<'_, T>> where
T: Variant + Clone,
[src]
T: Variant + Clone,
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]
Cast the Dynamic
as a unit ()
and return it.
Returns the name of the actual type if the cast fails.
pub fn as_int(&self) -> Result<i32, &'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_bool(&self) -> Result<bool, &'static str>
[src]
pub fn as_char(&self) -> Result<char, &'static str>
[src]
pub fn take_string(self) -> Result<String, &'static str>
[src]
Convert 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.
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 Clone for Dynamic
[src]
pub fn clone(&self) -> Dynamic
[src]
Clone the Dynamic
value.
WARNING
The cloned copy is marked read-write even if the original is read-only.
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Dynamic
[src]
impl Default for Dynamic
[src]
impl<'d> Deserialize<'d> for Dynamic
[src]
pub fn deserialize<D>(de: D) -> Result<Dynamic, <D as Deserializer<'d>>::Error> where
D: Deserializer<'d>,
[src]
D: Deserializer<'d>,
impl Display for Dynamic
[src]
impl<'_, T> From<&'_ [T]> for Dynamic where
T: Variant + Clone,
[src]
T: Variant + Clone,
impl<'_> From<&'_ ImmutableString> for Dynamic
[src]
pub fn from(value: &ImmutableString) -> Dynamic
[src]
impl<'_> From<&'_ SmartString<Compact>> for Dynamic
[src]
impl From<()> for Dynamic
[src]
impl<K, T> From<BTreeMap<K, T>> for Dynamic where
T: Variant + Clone,
K: Into<SmartString<Compact>>,
[src]
T: Variant + Clone,
K: Into<SmartString<Compact>>,
impl From<Box<FnPtr, Global>> for Dynamic
[src]
impl From<FnPtr> for Dynamic
[src]
impl<K, T> From<HashMap<K, T, RandomState>> for Dynamic where
T: Variant + Clone,
K: Into<SmartString<Compact>>,
[src]
T: Variant + Clone,
K: Into<SmartString<Compact>>,
pub fn from(value: HashMap<K, T, RandomState>) -> Dynamic
[src]
impl From<Instant> for Dynamic
[src]
impl<S> From<S> for Dynamic where
S: Into<ImmutableString>,
[src]
S: Into<ImmutableString>,
impl<T> From<Vec<T, Global>> for Dynamic where
T: Variant + Clone,
[src]
T: Variant + Clone,
impl From<bool> for Dynamic
[src]
impl From<char> for Dynamic
[src]
impl From<i32> for Dynamic
[src]
impl<T> FromIterator<T> for Dynamic where
T: Variant + Clone,
[src]
T: Variant + Clone,
pub fn from_iter<X>(iter: X) -> Dynamic where
X: IntoIterator<Item = T>,
[src]
X: IntoIterator<Item = T>,
impl Hash for Dynamic
[src]
pub fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Serialize for Dynamic
[src]
pub fn serialize<S>(
&self,
ser: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
&self,
ser: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CallHasher for T where
T: Hash + ?Sized,
T: Hash + ?Sized,
pub default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64 where
B: BuildHasher,
H: Hash + ?Sized,
B: BuildHasher,
H: Hash + ?Sized,
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
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.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,