Skip to content

Commit

Permalink
simple macros work
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandros committed Oct 22, 2024
1 parent aeeec86 commit 2229835
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ferrunix-macros/src/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ fn registration_fields(
let dependency_tuple = into_dependency_tuple(&fields);
let dependency_idents = into_dependency_idents(&fields);
let constructor = type_ctor(registered_ty, input, &fields)?;
let constructor = box_if_required(&constructor);
let ifawait = await_if_needed();

let tokens = match (dependency_tuple, dependency_idents) {
(Some(types), Some(idents)) => {
Expand All @@ -151,15 +153,15 @@ fn registration_fields(
.with_deps::<#registered_ty, #types>()
.#dependency_type(|#idents| {
#constructor
});
})#ifawait;
}
}

_ => {
quote! {
registry.#dependency_type::<#registered_ty>(|| {
#constructor
});
})#ifawait;
}
}
};
Expand Down
18 changes: 13 additions & 5 deletions ferrunix/tests/it/derive_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use ferrunix::{Inject, RegistrationFunc, Registry};

#[derive(Inject)]
#[provides(transient)]
struct Empty {}
// #[derive(Inject)]
// #[provides(transient)]
// struct Empty {}

// #[automatically_derived]
// impl Empty {
Expand All @@ -25,11 +25,19 @@ struct Empty {}
// }
// }

ferrunix::autoregister!(RegistrationFunc::new(Empty::register));
// ferrunix::autoregister!(RegistrationFunc::new(Empty::register));

#[derive(Inject)]
#[provides(transient = "StringTemplate")]
struct StringTemplate {
#[inject(ctor = r#""The Magic Number is ""#)]
raw: &'static str,
}


#[tokio::test]
async fn simple_derive() {
let registry = Registry::autoregistered().await;

let _obj = registry.get_transient::<Empty>().await.unwrap();
// let _obj = registry.get_transient::<Empty>().await.unwrap();
}

0 comments on commit 2229835

Please sign in to comment.