aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-03 20:23:26 +0200
committerHampusM <hampus@hampusmat.com>2022-10-03 20:45:32 +0200
commit97c789e38bb8e61389a3808d241689e623144344 (patch)
tree4cbaee424bfcb1b69a523be9664e48e5264f3d4b
parent03d3898a05592eb83b7a16609dba46d0b293790e (diff)
refactor: remove relying on Rust nightly for better handling of features
-rw-r--r--Cargo.toml1
-rw-r--r--macros/Cargo.toml1
-rw-r--r--macros/src/lib.rs14
-rw-r--r--src/async_di_container.rs16
-rw-r--r--src/di_container.rs8
-rw-r--r--src/errors/mod.rs5
-rw-r--r--src/interfaces/mod.rs5
-rw-r--r--src/lib.rs18
-rw-r--r--src/ptr.rs19
9 files changed, 49 insertions, 38 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 69be54b..7c5f905 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,7 +45,6 @@ strum_macros = "0.24.3"
paste = "1.0.8"
async-trait = { version = "0.1.57", optional = true }
tokio = { version = "1.20.1", features = ["sync"], optional = true }
-feature_macros = "0.1.0"
[dev_dependencies]
mockall = "0.11.1"
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index 205e9fe..ff55afe 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -26,7 +26,6 @@ proc-macro2 = "1.0.40"
uuid = { version = "0.8", features = ["v4"] }
regex = "1.6.0"
once_cell = "1.13.1"
-feature_macros = "0.1.0"
[dev_dependencies]
syrette = { version = "0.4.0", path = "..", features = ["factory"] }
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 8e906d0..293ac06 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -1,5 +1,4 @@
#![cfg_attr(doc_cfg, feature(doc_cfg))]
-#![feature(proc_macro_hygiene)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
@@ -7,7 +6,6 @@
//! Macros for the [Syrette](https://crates.io/crates/syrette) crate.
-use feature_macros::feature_specific;
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse, parse_macro_input};
@@ -18,10 +16,12 @@ mod libs;
mod macro_flag;
mod util;
-#[feature_specific("factory")]
+#[cfg(feature = "factory")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
mod factory;
-#[feature_specific("factory")]
+#[cfg(feature = "factory")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
mod fn_trait;
use crate::declare_interface_args::DeclareInterfaceArgs;
@@ -193,7 +193,8 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// ```
///
/// [`TransientPtr`]: https://docs.rs/syrette/latest/syrette/ptr/type.TransientPtr.html
-#[feature_specific("factory")]
+#[cfg(feature = "factory")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
#[proc_macro_attribute]
pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> TokenStream
{
@@ -291,7 +292,8 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke
/// declare_default_factory!(dyn IParser);
/// ```
#[proc_macro]
-#[feature_specific("factory")]
+#[cfg(feature = "factory")]
+#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream
{
use syn::parse_str;
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;
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<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")))
);
}