aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/fn_trait.rs20
-rw-r--r--macros/src/lib.rs7
2 files changed, 25 insertions, 2 deletions
diff --git a/macros/src/fn_trait.rs b/macros/src/fn_trait.rs
index f9b3514..9820f02 100644
--- a/macros/src/fn_trait.rs
+++ b/macros/src/fn_trait.rs
@@ -2,7 +2,7 @@ use quote::ToTokens;
use syn::parse::Parse;
use syn::punctuated::Punctuated;
use syn::token::Paren;
-use syn::{parenthesized, Ident, Token, Type};
+use syn::{parenthesized, parse_str, Ident, Token, TraitBound, Type};
/// A function trait. `dyn Fn(u32) -> String`
#[derive(Debug, Clone)]
@@ -14,6 +14,15 @@ pub struct FnTrait
pub inputs: Punctuated<Type, Token![,]>,
pub r_arrow_token: Token![->],
pub output: Type,
+ pub trait_bounds: Punctuated<TraitBound, Token![+]>,
+}
+
+impl FnTrait
+{
+ pub fn add_trait_bound(&mut self, trait_bound: TraitBound)
+ {
+ self.trait_bounds.push(trait_bound);
+ }
}
impl Parse for FnTrait
@@ -45,6 +54,7 @@ impl Parse for FnTrait
inputs,
r_arrow_token,
output,
+ trait_bounds: Punctuated::new(),
})
}
}
@@ -64,5 +74,13 @@ impl ToTokens for FnTrait
self.r_arrow_token.to_tokens(tokens);
self.output.to_tokens(tokens);
+
+ if !self.trait_bounds.is_empty() {
+ let plus: Token![+] = parse_str("+").unwrap();
+
+ plus.to_tokens(tokens);
+
+ self.trait_bounds.to_tokens(tokens);
+ }
}
}
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 2cd57f0..b0ccc86 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -6,7 +6,7 @@
use proc_macro::TokenStream;
use quote::quote;
-use syn::{parse, parse_macro_input};
+use syn::{parse, parse_macro_input, parse_str};
mod decl_def_factory_args;
mod declare_interface_args;
@@ -236,6 +236,11 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke
)
.unwrap();
+ if is_threadsafe {
+ factory_interface.add_trait_bound(parse_str("Send").unwrap());
+ factory_interface.add_trait_bound(parse_str("Sync").unwrap());
+ }
+
type_alias.ty = Box::new(Type::Verbatim(factory_interface.to_token_stream()));
let decl_interfaces = if is_threadsafe {