MetaCallValue

Trait MetaCallValue 

Source
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

Source

pub fn is<T: MetaCallValue>(&self) -> bool

Checks if the trait object is having the given type.

Source

pub fn downcast<T: MetaCallValue>(self: Box<Self>) -> Result<T, Box<Self>>

Downcasts the inner value of the trait object and returns the ownership.

Source

pub fn downcast_ref<T: MetaCallValue>(&self) -> Option<&T>

Downcasts the inner value of the trait object and returns a reference.

Source

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 + '_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Clone for Box<dyn MetaCallValue + Send + '_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Clone for Box<dyn MetaCallValue + Send + Sync + '_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Clone for Box<dyn MetaCallValue + Sync + '_>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl MetaCallValue for Box<dyn MetaCallValue>

Just a Rust barrier made for easier polymorphism.

Implementations on Foreign Types§

Source§

impl MetaCallValue for bool

Equivalent to MetaCall boolean type.

Source§

impl MetaCallValue for char

Equivalent to MetaCall char type.

Source§

impl MetaCallValue for f32

Equivalent to MetaCall float type.

Source§

impl MetaCallValue for f64

Equivalent to MetaCall double type.

Source§

impl MetaCallValue for i16

Equivalent to MetaCall short type.

Source§

impl MetaCallValue for i32

Equivalent to MetaCall int type.

Source§

impl MetaCallValue for i64

Equivalent to MetaCall long type.

Source§

impl MetaCallValue for Box<dyn MetaCallValue>

Just a Rust barrier made for easier polymorphism.

Source§

impl MetaCallValue for String

Equivalent to MetaCall string type.

Source§

impl MetaCallValue for Vec<i8>

Equivalent to MetaCall buffer type.

Source§

impl<T: MetaCallValue + Clone> MetaCallValue for Vec<T>

Equivalent to MetaCall array type.

Source§

impl<T: MetaCallValue + Clone> MetaCallValue for HashMap<String, T>

Equivalent to MetaCall map type.

Implementors§

Source§

impl MetaCallValue for MetaCallClass

Equivalent to MetaCall class type.

Source§

impl MetaCallValue for MetaCallException

Equivalent to MetaCall exception type.

Source§

impl MetaCallValue for MetaCallFunction

Equivalent to MetaCall function type.

Source§

impl MetaCallValue for MetaCallFuture

Equivalent to MetaCall future type.

Source§

impl MetaCallValue for MetaCallNull

Equivalent to MetaCall null type.

Source§

impl MetaCallValue for MetaCallObject

Equivalent to MetaCall object type.

Source§

impl MetaCallValue for MetaCallPointer

Equivalent to MetaCall pointer type.

Source§

impl MetaCallValue for MetaCallThrowable

Equivalent to MetaCall throwable type.