diff options
author | HampusM <hampus@hampusmat.com> | 2023-12-22 12:33:35 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-12-22 12:50:58 +0100 |
commit | 60c6ce824c1b19adc86d893053010e1de52c3265 (patch) | |
tree | eaa40fbe578a58ff8f40b4a993335d39254aa5c0 /macros/src/lib.rs | |
parent | 0f2756536e8fc311119da2af5b4dcc33f41bec6e (diff) |
feat: add support for async constructors
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r-- | macros/src/lib.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index fa84e0e..e55e23f 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -100,6 +100,30 @@ const PACKAGE_VERSION: &str = env!("CARGO_PKG_VERSION"); /// } /// } /// ``` +/// <br> +/// +/// When the `async` crate feature is enabled, the constructor can be [`async`]. +/// ``` +/// # #[cfg(feature = "async")] +/// # mod example { +/// # use syrette::injectable; +/// # +/// # struct PasswordManager { value: u32} +/// # +/// # async fn some_async_computation() -> u32 { 1 } +/// # +/// #[injectable(async = true)] +/// impl PasswordManager +/// { +/// pub async fn new() -> Self +/// { +/// let value = some_async_computation().await; +/// +/// Self { value } +/// } +/// } +/// # } +/// ``` /// /// # Attributes /// Attributes specific to impls with this attribute macro. @@ -149,6 +173,7 @@ const PACKAGE_VERSION: &str = env!("CARGO_PKG_VERSION"); /// [`Injectable`]: ../syrette/interfaces/injectable/trait.Injectable.html /// [`AsyncInjectable`]: ../syrette/interfaces/async_injectable/trait.AsyncInjectable.html /// [`di_container_bind`]: ../syrette/macro.di_container_bind.html +/// [`async`]: https://doc.rust-lang.org/std/keyword.async.html #[cfg(not(tarpaulin_include))] #[proc_macro_error] #[proc_macro_attribute] @@ -233,7 +258,7 @@ pub fn injectable(args_stream: TokenStream, input_stream: TokenStream) -> TokenS let injectable_impl = InjectableImpl::<Dependency>::new(item_impl, &constructor).unwrap_or_abort(); - injectable_impl.validate().unwrap_or_abort(); + injectable_impl.validate(is_async).unwrap_or_abort(); let expanded_injectable_impl = injectable_impl.expand(no_doc_hidden, is_async); |