chassis 0.2.0

Compile-time dependency injection framework
Documentation
use chassis::{AssembleError, AssembleErrors, TypeInfo};

fn errors<T>(res: &Result<T, AssembleErrors>) -> &[AssembleError] {
    match res {
        Ok(_) => &[],
        Err(errors) => errors.as_slice(),
    }
}

#[test]
fn missing_dep_provider() {
    pub struct StringArg(String);

    #[derive(Default)]
    pub struct Module;

    #[chassis::module]
    impl Module {
        pub fn missing_dep(s: String) -> StringArg {
            StringArg(s)
        }
    }

    #[chassis::injector(modules = [Module])]
    pub trait Factory {
        fn resolve(&self) -> StringArg;
    }

    let factory = <dyn Factory>::new();
    let errors = errors(&factory);

    assert_eq!(
        vec![AssembleError::MissingImplementation {
            ty: TypeInfo::of::<String>()
        }],
        errors
    );
}

#[test]
fn missing_root_product_provider() {
    #[derive(Default)]
    pub struct Module;

    #[chassis::module]
    impl Module {}

    #[chassis::injector(modules = [Module])]
    pub trait Factory {
        fn resolve(&self) -> String;
    }

    let factory = <dyn Factory>::new();
    let errors = errors(&factory);

    println!("{}", errors[0]);
    assert_eq!(
        vec![AssembleError::MissingImplementation {
            ty: TypeInfo::of::<String>()
        }],
        errors
    );
}