Crate query_interface [−] [src]
query-interface - dynamically query a type-erased object for any trait implementation
#[macro_use] extern crate query_interface; use query_interface::{Object, ObjectClone}; use std::fmt::Debug; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] struct Foo; interfaces!(Foo: ObjectClone, Debug, Bar); trait Bar { fn do_something(&self); } impl Bar for Foo { fn do_something(&self) { println!("I'm a Foo!"); } } fn main() { let obj = Box::new(Foo) as Box<Object>; let obj2 = obj.clone(); println!("{:?}", obj2); obj2.query_ref::<Bar>().unwrap().do_something(); // Prints: "I'm a Foo!" }
Macros
interfaces |
Allow a set of traits to be dynamically queried from a type when it is
stored as an |
mopo |
Define a custom Object-like trait. The |
Traits
HasInterface |
You can use this trait to ensure that a type implements a trait as an
interface. This means the type declared the trait in its |
Object |
This trait is the primary function of the library. |
ObjectClone |
This is an object-safe version of |
ObjectEq |
This is an object-safe version of |
ObjectHash |
This is an object-safe version of |
ObjectOrd |
This is an object-safe version of |
ObjectPartialEq |
This is an object-safe version of |
ObjectPartialOrd |
This is an object-safe version of |