diff options
author | HampusM <hampus@hampusmat.com> | 2022-10-03 20:23:26 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-10-03 20:45:32 +0200 |
commit | 97c789e38bb8e61389a3808d241689e623144344 (patch) | |
tree | 4cbaee424bfcb1b69a523be9664e48e5264f3d4b /src | |
parent | 03d3898a05592eb83b7a16609dba46d0b293790e (diff) |
refactor: remove relying on Rust nightly for better handling of features
Diffstat (limited to 'src')
-rw-r--r-- | src/async_di_container.rs | 16 | ||||
-rw-r--r-- | src/di_container.rs | 8 | ||||
-rw-r--r-- | src/errors/mod.rs | 5 | ||||
-rw-r--r-- | src/interfaces/mod.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 18 | ||||
-rw-r--r-- | src/ptr.rs | 19 |
6 files changed, 41 insertions, 30 deletions
diff --git a/src/async_di_container.rs b/src/async_di_container.rs index ab74b4c..3943dae 100644 --- a/src/async_di_container.rs +++ b/src/async_di_container.rs @@ -54,7 +54,6 @@ 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")] @@ -79,7 +78,8 @@ use crate::provider::r#async::{ use crate::ptr::{SomeThreadsafePtr, ThreadsafeSingletonPtr, TransientPtr}; /// Alias for a threadsafe boxed function. -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub type BoxFn<Args, Return> = Box<(dyn Fn<Args, Output = Return> + Send + Sync)>; /// When configurator for a binding for type 'Interface' inside a [`AsyncDIContainer`]. @@ -330,7 +330,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub async fn to_factory<Args, Return, FactoryFunc>( &self, factory_func: &'static FactoryFunc, @@ -415,7 +416,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub async fn to_async_factory<Args, Return, FactoryFunc>( &self, factory_func: &'static FactoryFunc, @@ -501,7 +503,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub async fn to_default_factory<Return, FactoryFunc>( &self, factory_func: &'static FactoryFunc, @@ -587,7 +590,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub async fn to_async_default_factory<Return, FactoryFunc>( &self, factory_func: &'static FactoryFunc, diff --git a/src/di_container.rs b/src/di_container.rs index b23cdb1..2ed1e25 100644 --- a/src/di_container.rs +++ b/src/di_container.rs @@ -54,8 +54,6 @@ use std::cell::RefCell; use std::marker::PhantomData; use std::rc::Rc; -use feature_macros::feature_specific; - #[cfg(feature = "factory")] use crate::castable_factory::blocking::CastableFactory; use crate::di_container_binding_map::DIContainerBindingMap; @@ -333,7 +331,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub fn to_factory<Args, Return, Func>( &self, factory_func: &'static Func, @@ -420,7 +419,8 @@ where /// # Ok(()) /// # } /// ``` - #[feature_specific("factory")] + #[cfg(feature = "factory")] + #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub fn to_default_factory<Return, FactoryFunc>( &self, factory_func: &'static FactoryFunc, diff --git a/src/errors/mod.rs b/src/errors/mod.rs index a1eb551..7eb10bd 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -1,10 +1,9 @@ //! Error types for various components of the library. -use feature_macros::feature_specific; - pub mod di_container; pub mod injectable; pub mod ptr; -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] pub mod async_di_container; diff --git a/src/interfaces/mod.rs b/src/interfaces/mod.rs index 65bac12..9815a11 100644 --- a/src/interfaces/mod.rs +++ b/src/interfaces/mod.rs @@ -1,7 +1,5 @@ //! Various useful interfaces. -use feature_macros::feature_specific; - pub mod injectable; #[cfg(feature = "factory")] @@ -12,5 +10,6 @@ pub mod any_factory; #[doc(hidden)] pub mod factory; -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] pub mod async_injectable; @@ -1,6 +1,5 @@ #![cfg_attr(feature = "factory", feature(unboxed_closures, fn_traits))] #![cfg_attr(doc_cfg, feature(doc_cfg))] -#![feature(proc_macro_hygiene)] #![deny(clippy::all)] #![deny(clippy::pedantic)] #![allow(clippy::module_name_repetitions)] @@ -10,23 +9,25 @@ //! //! Syrette is a collection of utilities useful for performing dependency injection. -use feature_macros::feature_specific; - pub mod di_container; pub mod errors; pub mod interfaces; pub mod ptr; -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] pub mod async_di_container; -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] pub mod future; -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] pub use async_di_container::AsyncDIContainer; pub use di_container::DIContainer; -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub use syrette_macros::{declare_default_factory, factory}; pub use syrette_macros::{declare_interface, injectable, named}; @@ -122,7 +123,8 @@ macro_rules! di_container_bind { /// }) /// }); /// ``` -#[feature_specific("async")] +#[cfg(feature = "async")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))] #[macro_export] macro_rules! async_closure { (|$($args: ident),*| { $($inner: stmt);* }) => { @@ -2,7 +2,6 @@ use std::rc::Rc; use std::sync::Arc; -use feature_macros::feature_specific; use paste::paste; use crate::errors::ptr::{SomePtrError, SomeThreadsafePtrError}; @@ -17,11 +16,13 @@ pub type SingletonPtr<Interface> = Rc<Interface>; pub type ThreadsafeSingletonPtr<Interface> = Arc<Interface>; /// A smart pointer to a factory. -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub type FactoryPtr<FactoryInterface> = Rc<FactoryInterface>; /// A threadsafe smart pointer to a factory. -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub type ThreadsafeFactoryPtr<FactoryInterface> = Arc<FactoryInterface>; macro_rules! create_as_variant_fn { @@ -37,7 +38,7 @@ macro_rules! create_as_variant_fn { "# Errors\n" "Will return Err if it's not the `" [<$variant>] "` variant." ] - $(#[$attrs]),* + $(#[$attrs])* pub fn [<$variant:snake>](self) -> Result<[<$variant Ptr>]<Interface>, [<$enum Error>]> { if let $enum::$variant(ptr) = self { @@ -79,7 +80,12 @@ where create_as_variant_fn!(SomePtr, Singleton); - create_as_variant_fn!(SomePtr, Factory, feature_specific("factory")); + create_as_variant_fn!( + SomePtr, + Factory, + cfg(feature = "factory"), + cfg_attr(doc_cfg, doc(cfg(feature = "factory"))) + ); } /// Some threadsafe smart pointer. @@ -111,6 +117,7 @@ where create_as_variant_fn!( SomeThreadsafePtr, ThreadsafeFactory, - feature_specific("factory") + cfg(feature = "factory"), + cfg_attr(doc_cfg, doc(cfg(feature = "factory"))) ); } |