pub trait MetaCallValue:
MetaCallClone
+ MetaCallDowncast
+ Debug { }
Expand description
Trait of any possible object in MetaCall. Checkout match_metacall_value macro for matching trait objects of this trait. Let’ see what types we can use with an example: …
// bool
metacall::metacall_untyped("x", [true, false]);
// char
metacall::metacall_untyped("x", ['A', 'Z']);
// short
metacall::metacall_untyped("x", [5 as i16]);
// int
metacall::metacall_untyped("x", [5 as i32]);
// long
metacall::metacall_untyped("x", [5 as i64]);
// float
metacall::metacall_untyped("x", [5.0 as f32]);
// double
metacall::metacall_untyped("x", [5.0 as f64]);
// string
metacall::metacall_untyped("x", [String::from("hi")]);
// buffer
metacall::metacall_untyped("x", [
String::from("hi")
.as_bytes()
.iter()
.map(|&b| b as i8)
.collect::<Vec<i8>>()
]);
// array
metacall::metacall_untyped("x", [vec![5, 6]]);
// map
let mut hashmap = std::collections::HashMap::new();
hashmap.insert(String::from("hi"), String::from("there!"));
metacall::metacall_untyped("x", [hashmap]);
// pointer
metacall::metacall_untyped("x", [metacall::MetaCallPointer::new(String::from("hi"))]);
// future?
// nope! you can't pass a future!
// function
metacall::metacall_untyped("x", [
metacall::metacall_no_arg::<metacall::MetaCallFunction>("my_async_function").unwrap()
]);
// null
metacall::metacall_untyped("x", [metacall::MetaCallNull()]);
// class
metacall::metacall_untyped("x", [metacall::MetaCallClass::from_name("MyClass").unwrap()]);
// object
let class = metacall::MetaCallClass::from_name("MyClass").unwrap();
metacall::metacall_untyped("x", [class.create_object_no_arg("myObject").unwrap()]);
// exception
metacall::metacall_untyped("x", [
metacall::metacall_no_arg::<metacall::MetaCallException>("my_function").unwrap()
]);
// throwable?
// nope! you can't pass a throwable!
Implementations§
Source§impl dyn MetaCallValue
impl dyn MetaCallValue
Sourcepub fn is<T: MetaCallValue>(&self) -> bool
pub fn is<T: MetaCallValue>(&self) -> bool
Checks if the trait object is having the given type.
Sourcepub fn downcast<T: MetaCallValue>(self: Box<Self>) -> Result<T, Box<Self>>
pub fn downcast<T: MetaCallValue>(self: Box<Self>) -> Result<T, Box<Self>>
Downcasts the inner value of the trait object and returns the ownership.
Sourcepub fn downcast_ref<T: MetaCallValue>(&self) -> Option<&T>
pub fn downcast_ref<T: MetaCallValue>(&self) -> Option<&T>
Downcasts the inner value of the trait object and returns a reference.
Sourcepub fn downcast_mut<T: MetaCallValue>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: MetaCallValue>(&mut self) -> Option<&mut T>
Downcasts the inner value of the trait object and returns a mutable reference.
Trait Implementations§
Source§impl Clone for Box<dyn MetaCallValue + '_>
impl Clone for Box<dyn MetaCallValue + '_>
impl MetaCallValue for Box<dyn MetaCallValue>
Just a Rust barrier made for easier polymorphism.
Implementations on Foreign Types§
impl MetaCallValue for bool
Equivalent to MetaCall boolean type.
impl MetaCallValue for char
Equivalent to MetaCall char type.
impl MetaCallValue for f32
Equivalent to MetaCall float type.
impl MetaCallValue for f64
Equivalent to MetaCall double type.
impl MetaCallValue for i16
Equivalent to MetaCall short type.
impl MetaCallValue for i32
Equivalent to MetaCall int type.
impl MetaCallValue for i64
Equivalent to MetaCall long type.
impl MetaCallValue for Box<dyn MetaCallValue>
Just a Rust barrier made for easier polymorphism.
impl MetaCallValue for String
Equivalent to MetaCall string type.
impl MetaCallValue for Vec<i8>
Equivalent to MetaCall buffer type.
impl<T: MetaCallValue + Clone> MetaCallValue for Vec<T>
Equivalent to MetaCall array type.
impl<T: MetaCallValue + Clone> MetaCallValue for HashMap<String, T>
Equivalent to MetaCall map type.
Implementors§
impl MetaCallValue for MetaCallClass
Equivalent to MetaCall class type.
impl MetaCallValue for MetaCallException
Equivalent to MetaCall exception type.
impl MetaCallValue for MetaCallFunction
Equivalent to MetaCall function type.
impl MetaCallValue for MetaCallFuture
Equivalent to MetaCall future type.
impl MetaCallValue for MetaCallNull
Equivalent to MetaCall null type.
impl MetaCallValue for MetaCallObject
Equivalent to MetaCall object type.
impl MetaCallValue for MetaCallPointer
Equivalent to MetaCall pointer type.
impl MetaCallValue for MetaCallThrowable
Equivalent to MetaCall throwable type.