Trait metafactory::MetaFactoryUnstable
[-]
[+]
[src]
pub trait MetaFactory { fn get_type(&self) -> TypeDef; fn get_arg_types(&self) -> Vec<TypeDef>; fn new(&self, arg_getters: Vec<Box<Any>>) -> Result<Box<Any>, FactoryErrorKind>; fn new_aggregate(&self) -> Aggregate<'static>; }
Implements reflection and initiation of any abstract object constructor.
Information about constructor
The first goal of this trait is being able to inspect the construction mechanism at the runtime.
MetaFactory
contains information about the constructor source: the
return type and argument types. It also contains a method new
that can create a function to invoke this source and get the values.
Factory initiation
The second goal is to avoid donwcasting construction arguments on every
Factory
invocation.
There are separate traits for MetaFactory
and "real" Factory
.
MetaFactory
is used to build a real Factory
by passing all the
required constructor arguments as factories under Vec<Box<Any>>
.
Internaly, all parent Factory
s will be downcasted to correct types
and stored inside returned Factory
's scope, so that all of them
can be invoked with a simple take()
call.
Simple value as constructor
This library allows to use many sources as "constructors", the simplest of which is a cloneable value. In this example we will use such value to create a new constructor metadata, check if argument and return types are correct, and then create an actual getter for the value:
use metafactory::{ metafactory, AsFactoryExt }; let metafactory = metafactory(5i); assert!(metafactory.get_type().is::<int>()); assert!(metafactory.get_arg_types().len() == 0); // clonable int has no arguments let factory = metafactory .new( Vec::new() // No arguments in this case. ) .ok().unwrap() .as_factory_of::<int>() .unwrap(); assert_eq!(factory.take(), 5i);
Required Methods
fn get_type(&self) -> TypeDef
fn get_arg_types(&self) -> Vec<TypeDef>
fn new(&self, arg_getters: Vec<Box<Any>>) -> Result<Box<Any>, FactoryErrorKind>
fn new_aggregate(&self) -> Aggregate<'static>
Implementors
impl<T: 'static> MetaFactory for Rc<RefCell<|| -> T>>
impl<A: 'static, T: 'static> MetaFactory for Rc<RefCell<|A| -> T>>
impl<A1: 'static, A2: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, A8: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7, A8| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, A8: 'static, A9: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7, A8, A9| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, A8: 'static, A9: 'static, A10: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7, A8, A9, A10| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, A8: 'static, A9: 'static, A10: 'static, A11: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11| -> T>>
impl<A1: 'static, A2: 'static, A3: 'static, A4: 'static, A5: 'static, A6: 'static, A7: 'static, A8: 'static, A9: 'static, A10: 'static, A11: 'static, A12: 'static, T: 'static> MetaFactory for Rc<RefCell<|A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12| -> T>>