From 97c789e38bb8e61389a3808d241689e623144344 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 3 Oct 2022 20:23:26 +0200 Subject: refactor: remove relying on Rust nightly for better handling of features --- src/async_di_container.rs | 16 ++++++++++------ src/di_container.rs | 8 ++++---- src/errors/mod.rs | 5 ++--- src/interfaces/mod.rs | 5 ++--- src/lib.rs | 18 ++++++++++-------- src/ptr.rs | 19 +++++++++++++------ 6 files changed, 41 insertions(+), 30 deletions(-) (limited to 'src') 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 = Box<(dyn Fn + 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( &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( &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( &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( &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( &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( &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; diff --git a/src/lib.rs b/src/lib.rs index 2cd2f03..a462c21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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);* }) => { diff --git a/src/ptr.rs b/src/ptr.rs index 824b086..46418d1 100644 --- a/src/ptr.rs +++ b/src/ptr.rs @@ -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 = Rc; pub type ThreadsafeSingletonPtr = Arc; /// A smart pointer to a factory. -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub type FactoryPtr = Rc; /// A threadsafe smart pointer to a factory. -#[feature_specific("factory")] +#[cfg(feature = "factory")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] pub type ThreadsafeFactoryPtr = Arc; 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>], [<$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"))) ); } -- cgit v1.2.3-18-g5258