metafactory

Crates.iometafactory
lib.rsmetafactory
version0.4.4
sourcesrc
created_at2014-12-08 21:46:54.370559
updated_at2015-12-11 23:54:29.779751
descriptionRust library to chain together object factories.
homepage
repositoryhttps://github.com/Nercury/metafactory-rs
max_upload_size
id491
size44,377
Nerijus Arlauskas (Nercury)

documentation

http://nercury.github.io/metafactory-rs/metafactory/index.html

README

MetaFactory

Build value factory chains at runtime from lambdas and other sources.

Build Status

Quick example

use metafactory::{ metafactory, argless_as_factory, AsFactoryExt };

fn main() {
    // initialization

    let meta_sum = metafactory(
        |a: int, b: int| a + b
    );

    let meta_twice = metafactory(
        |val: int| val * 2
    );

    // plugging in

    let any_factory = meta_twice.new(vec![
        meta_sum.new(vec![
            argless_as_factory(3i),
            argless_as_factory(2i),
        ]).ok().unwrap()
    ]).ok().unwrap();

    // using

    let getter = any_factory.as_factory_of::<int>().unwrap();

    // note that "take" requires no arguments

    assert_eq!(getter.take().value, 12);
}

Offers primitive reflection for returned factory type and arguments:

let meta_int = metafactory(
    |arg: bool| i32
);

// it knows the source returns 32-bit int
assert!(meta_int.get_type().is::<i32>());

// it knows the argument is bool
assert!(meta_int.get_arg_types().get(0).unwrap().is::<bool>());

Usage

Put this in your Cargo.toml:

[dependencies]
metafactory = "*"

And this in your crate root:

extern crate metafactory;

Resources

License

MIT

Commit count: 44

cargo fmt