From d8525f169649e4ce7e806e68de5e328135755326 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 2 Oct 2022 19:32:25 +0200 Subject: refactor: improve management of feature specific items --- src/async_di_container.rs | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/async_di_container.rs') diff --git a/src/async_di_container.rs b/src/async_di_container.rs index f8ce92d..881f64c 100644 --- a/src/async_di_container.rs +++ b/src/async_di_container.rs @@ -50,14 +50,11 @@ //! Ok(()) //! } //! ``` -//! -//! --- -//! -//! *This module is only available if Syrette is built with the "async" feature.* use std::any::type_name; use std::marker::PhantomData; use std::sync::Arc; +use feature_macros::feature_specific; use tokio::sync::Mutex; #[cfg(feature = "factory")] @@ -82,6 +79,7 @@ use crate::provider::r#async::{ use crate::ptr::{SomeThreadsafePtr, ThreadsafeSingletonPtr, TransientPtr}; /// Alias for a threadsafe boxed function. +#[feature_specific("factory")] pub type BoxFn = Box<(dyn Fn + Send + Sync)>; /// When configurator for a binding for type 'Interface' inside a [`AsyncDIContainer`]. @@ -289,11 +287,9 @@ where /// Creates a binding of factory type `Interface` to a factory inside of the /// associated [`AsyncDIContainer`]. /// - /// *This function is only available if Syrette is built with the "factory" feature.* - /// /// # Errors - /// Will return Err if the associated [`AsyncDIContainer`] already have a binding for - /// the interface. + /// Will return Err if the associated [`AsyncDIContainer`] already have a binding + /// for the interface. /// /// # Examples /// ``` @@ -334,7 +330,7 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(feature = "factory")] + #[feature_specific("factory")] pub async fn to_factory( &self, factory_func: &'static FactoryFunc, @@ -373,11 +369,9 @@ where /// Creates a binding of factory type `Interface` to a async factory inside of the /// associated [`AsyncDIContainer`]. /// - /// *This function is only available if Syrette is built with the "factory" feature.* - /// /// # Errors - /// Will return Err if the associated [`AsyncDIContainer`] already have a binding for - /// the interface. + /// Will return Err if the associated [`AsyncDIContainer`] already have a binding + /// for the interface. /// /// # Examples /// ``` @@ -421,7 +415,7 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(all(feature = "factory", feature = "async"))] + #[feature_specific("factory")] pub async fn to_async_factory( &self, factory_func: &'static FactoryFunc, @@ -464,11 +458,9 @@ where /// Creates a binding of type `Interface` to a factory that takes no arguments /// inside of the associated [`AsyncDIContainer`]. /// - /// *This function is only available if Syrette is built with the "factory" feature.* - /// /// # Errors - /// Will return Err if the associated [`AsyncDIContainer`] already have a binding for - /// the interface. + /// Will return Err if the associated [`AsyncDIContainer`] already have a binding + /// for the interface. /// /// # Examples /// ``` @@ -509,7 +501,7 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(feature = "factory")] + #[feature_specific("factory")] pub async fn to_default_factory( &self, factory_func: &'static FactoryFunc, @@ -549,11 +541,9 @@ where /// Creates a binding of factory type `Interface` to a async factory inside of the /// associated [`AsyncDIContainer`]. /// - /// *This function is only available if Syrette is built with the "factory" feature.* - /// /// # Errors - /// Will return Err if the associated [`AsyncDIContainer`] already have a binding for - /// the interface. + /// Will return Err if the associated [`AsyncDIContainer`] already have a binding + /// for the interface. /// /// # Examples /// ``` @@ -597,7 +587,7 @@ where /// # Ok(()) /// # } /// ``` - #[cfg(all(feature = "factory", feature = "async"))] + #[feature_specific("factory")] pub async fn to_async_default_factory( &self, factory_func: &'static FactoryFunc, -- cgit v1.2.3-18-g5258