aboutsummaryrefslogtreecommitdiff
path: root/macros/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-04 12:51:06 +0200
committerHampusM <hampus@hampusmat.com>2023-10-04 12:52:22 +0200
commit0f2756536e8fc311119da2af5b4dcc33f41bec6e (patch)
tree0964efe0eaf855017c67fae52da8672a47becc65 /macros/src/lib.rs
parentc936439bfac9e35958f685a52abb51d781e70a7c (diff)
refactor!: remove factory & declare_default_factory macros
BREAKING CHANGE: The factory and the declare_default_factory macros have been removed. They are no longer needed to use factories
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r--macros/src/lib.rs158
1 files changed, 0 insertions, 158 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 7928e03..fa84e0e 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -35,12 +35,6 @@ mod injectable;
mod macro_flag;
mod util;
-#[cfg(feature = "factory")]
-mod factory;
-
-#[cfg(feature = "factory")]
-mod fn_trait;
-
#[cfg(test)]
mod test_utils;
@@ -277,158 +271,6 @@ pub fn injectable(args_stream: TokenStream, input_stream: TokenStream) -> TokenS
.into()
}
-/// Makes a type alias usable as a factory interface.
-///
-/// # Arguments
-/// * (Zero or more) Flags. Like `a = true, b = false`
-///
-/// # Flags
-/// - `threadsafe` - Mark as threadsafe.
-///
-/// # Examples
-/// ```
-/// # use syrette::factory;
-/// # use syrette::ptr::TransientPtr;
-/// #
-/// # trait IConfigurator {}
-/// #
-/// # struct Configurator {}
-/// #
-/// # impl Configurator
-/// # {
-/// # fn new() -> Self
-/// # {
-/// # Self {}
-/// # }
-/// # }
-/// #
-/// # impl IConfigurator for Configurator {}
-/// #
-/// #[factory]
-/// type IConfiguratorFactory = dyn Fn(Vec<String>) -> TransientPtr<dyn IConfigurator>;
-/// ```
-///
-/// [`TransientPtr`]: https://docs.rs/syrette/latest/syrette/ptr/type.TransientPtr.html
-#[cfg(feature = "factory")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
-#[cfg(not(tarpaulin_include))]
-#[proc_macro_error]
-#[proc_macro_attribute]
-pub fn factory(args_stream: TokenStream, input_stream: TokenStream) -> TokenStream
-{
- use crate::factory::build_declare_interfaces::build_declare_factory_interfaces;
- use crate::factory::macro_args::FactoryMacroArgs;
- use crate::factory::type_alias::FactoryTypeAlias;
-
- set_dummy(input_stream.clone().into());
-
- let FactoryMacroArgs { flags } = parse(args_stream).unwrap_or_abort();
-
- let is_threadsafe = flags
- .iter()
- .find(|flag| flag.name() == "threadsafe")
- .map_or(Ok(false), MacroFlag::get_bool)
- .unwrap_or_abort();
-
- let FactoryTypeAlias {
- type_alias,
- factory_interface,
- } = parse(input_stream).unwrap_or_abort();
-
- let decl_interfaces =
- build_declare_factory_interfaces(&factory_interface, is_threadsafe);
-
- quote! {
- #type_alias
-
- #decl_interfaces
- }
- .into()
-}
-
-/// Shortcut for declaring a default factory.
-///
-/// A default factory is a factory that doesn't take any arguments.
-///
-/// Another way to accomplish what this macro does would be by using
-/// the [`macro@factory`] macro.
-///
-/// # Arguments
-/// - Interface trait
-/// * (Zero or more) Flags. Like `a = true, b = false`
-///
-/// # Flags
-/// - `threadsafe` - Mark as threadsafe.
-/// - `async` - Mark as async. Infers the `threadsafe` flag.
-///
-/// # Examples
-/// ```
-/// # use syrette::declare_default_factory;
-/// #
-/// trait IParser
-/// {
-/// // Methods and etc here...
-/// }
-///
-/// declare_default_factory!(dyn IParser);
-/// ```
-#[cfg(feature = "factory")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))]
-#[cfg(not(tarpaulin_include))]
-#[proc_macro_error]
-#[proc_macro]
-pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream
-{
- use syn::parse_str;
-
- use crate::factory::build_declare_interfaces::build_declare_factory_interfaces;
- use crate::factory::declare_default_args::DeclareDefaultFactoryMacroArgs;
- use crate::fn_trait::FnTrait;
-
- let DeclareDefaultFactoryMacroArgs { interface, flags } =
- parse(args_stream).unwrap_or_abort();
-
- let mut is_threadsafe = flags
- .iter()
- .find(|flag| flag.name() == "threadsafe")
- .map_or(Ok(false), MacroFlag::get_bool)
- .unwrap_or_abort();
-
- let is_async = flags
- .iter()
- .find(|flag| flag.name() == "async")
- .map_or(Ok(false), MacroFlag::get_bool)
- .unwrap_or_abort();
-
- if is_async {
- is_threadsafe = true;
- }
-
- let mut factory_interface: FnTrait = parse(
- if is_async {
- quote! {
- dyn Fn() -> syrette::future::BoxFuture<
- 'static,
- syrette::ptr::TransientPtr<#interface>
- >
- }
- } else {
- quote! {
- dyn Fn() -> syrette::ptr::TransientPtr<#interface>
- }
- }
- .into(),
- )
- .unwrap_or_abort();
-
- if is_threadsafe {
- factory_interface.add_trait_bound(parse_str("Send").unwrap_or_abort());
- factory_interface.add_trait_bound(parse_str("Sync").unwrap_or_abort());
- }
-
- build_declare_factory_interfaces(&factory_interface, is_threadsafe).into()
-}
-
/// Declares the interface trait of a implementation.
///
/// # Arguments