diff options
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/declare_interface_args.rs | 12 | ||||
-rw-r--r-- | macros/src/factory/build_declare_interfaces.rs | 4 | ||||
-rw-r--r-- | macros/src/lib.rs | 15 |
3 files changed, 17 insertions, 14 deletions
diff --git a/macros/src/declare_interface_args.rs b/macros/src/declare_interface_args.rs index 79004da..fea6c7b 100644 --- a/macros/src/declare_interface_args.rs +++ b/macros/src/declare_interface_args.rs @@ -5,7 +5,7 @@ use syn::{Token, TypePath}; use crate::macro_flag::MacroFlag; use crate::util::iterator_ext::IteratorExt; -pub const DECLARE_INTERFACE_FLAGS: &[&str] = &["async"]; +pub const DECLARE_INTERFACE_FLAGS: &[&str] = &["threadsafe_sharable"]; pub struct DeclareInterfaceArgs { @@ -110,7 +110,7 @@ mod tests fn can_parse_with_flags() -> Result<(), Box<dyn Error>> { let input_args = quote! { - Foobar -> IFoobar, async = true + Foobar -> IFoobar, threadsafe_sharable = true }; let decl_interface_args = parse2::<DeclareInterfaceArgs>(input_args)?; @@ -140,7 +140,7 @@ mod tests assert_eq!( decl_interface_args.flags, Punctuated::from_iter(vec![MacroFlag { - name: format_ident!("async"), + name: format_ident!("threadsafe_sharable"), value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( true, Span::call_site() @@ -155,7 +155,7 @@ mod tests fn cannot_parse_with_invalid_flag() { let input_args = quote! { - Foobar -> IFoobar, xyz = false, async = true + Foobar -> IFoobar, xyz = false, threadsafe_sharable = true }; assert!(parse2::<DeclareInterfaceArgs>(input_args).is_err()); @@ -167,7 +167,7 @@ mod tests assert!( // Formatting is weird without this comment parse2::<DeclareInterfaceArgs>(quote! { - Foobar -> IFoobar, async = true, async = true + Foobar -> IFoobar, threadsafe_sharable = true, threadsafe_sharable = true }) .is_err() ); @@ -175,7 +175,7 @@ mod tests assert!( // Formatting is weird without this comment parse2::<DeclareInterfaceArgs>(quote! { - Foobar -> IFoobar, async = true, async = false + Foobar -> IFoobar, threadsafe_sharable = true, threadsafe_sharable = false }) .is_err() ); diff --git a/macros/src/factory/build_declare_interfaces.rs b/macros/src/factory/build_declare_interfaces.rs index 038d29d..e4fc01b 100644 --- a/macros/src/factory/build_declare_interfaces.rs +++ b/macros/src/factory/build_declare_interfaces.rs @@ -18,7 +18,7 @@ pub fn build_declare_factory_interfaces( (std::sync::Arc<syrette::AsyncDIContainer>,), #factory_interface >, - async = true + threadsafe_sharable = true ); syrette::declare_interface!( @@ -26,7 +26,7 @@ pub fn build_declare_factory_interfaces( (std::sync::Arc<syrette::AsyncDIContainer>,), #factory_interface > -> syrette::private::any_factory::AnyThreadsafeFactory, - async = true + threadsafe_sharable = true ); } } else { diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 80274fd..b261974 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -220,14 +220,14 @@ pub fn injectable(args_stream: TokenStream, input_stream: TokenStream) -> TokenS }); let maybe_decl_interface = if let Some(interface) = opt_interface { - let async_flag = if is_async { - quote! {, async = true} + let threadsafe_sharable_flag = if is_async { + quote! { , threadsafe_sharable = true } } else { quote! {} }; quote! { - syrette::declare_interface!(#self_type -> #interface #async_flag); + syrette::declare_interface!(#self_type -> #interface #threadsafe_sharable_flag); } } else { quote! {} @@ -443,7 +443,8 @@ pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream /// * (Zero or more) Flags. Like `a = true, b = false` /// /// # Flags -/// - `async` - Mark as async. +/// - `threadsafe_sharable` - Enables the use of thread-safe shared instances of the +/// implementation accessed with the interface. /// /// # Examples /// ``` @@ -468,9 +469,11 @@ pub fn declare_interface(input: TokenStream) -> TokenStream flags, } = parse(input).unwrap_or_abort(); - let opt_async_flag = flags.iter().find(|flag| flag.name() == "async"); + let threadsafe_sharable_flag = flags + .iter() + .find(|flag| flag.name() == "threadsafe_sharable"); - let is_async = opt_async_flag + let is_async = threadsafe_sharable_flag .map_or_else(|| Ok(false), MacroFlag::get_bool) .unwrap_or_abort(); |