aboutsummaryrefslogtreecommitdiff
path: root/macros/src/libs/intertrait_macros/gen_caster.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-29 20:52:56 +0200
committerHampusM <hampus@hampusmat.com>2022-08-29 21:01:32 +0200
commit080cc42bb1da09059dbc35049a7ded0649961e0c (patch)
tree307ee564124373616022c1ba2b4d5af80845cd92 /macros/src/libs/intertrait_macros/gen_caster.rs
parent6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff)
feat: implement async functionality
Diffstat (limited to 'macros/src/libs/intertrait_macros/gen_caster.rs')
-rw-r--r--macros/src/libs/intertrait_macros/gen_caster.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/macros/src/libs/intertrait_macros/gen_caster.rs b/macros/src/libs/intertrait_macros/gen_caster.rs
index 9bac09e..df743e2 100644
--- a/macros/src/libs/intertrait_macros/gen_caster.rs
+++ b/macros/src/libs/intertrait_macros/gen_caster.rs
@@ -22,15 +22,29 @@ const CASTER_FN_NAME_PREFIX: &[u8] = b"__";
const FN_BUF_LEN: usize = CASTER_FN_NAME_PREFIX.len() + Simple::LENGTH;
-pub fn generate_caster(ty: &impl ToTokens, dst_trait: &impl ToTokens) -> TokenStream
+pub fn generate_caster(
+ ty: &impl ToTokens,
+ dst_trait: &impl ToTokens,
+ sync: bool,
+) -> TokenStream
{
let fn_ident = create_caster_fn_ident();
- let new_caster = quote! {
- syrette::libs::intertrait::Caster::<dyn #dst_trait>::new(
- |from| from.downcast::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap(),
- )
+ let new_caster = if sync {
+ quote! {
+ syrette::libs::intertrait::Caster::<dyn #dst_trait>::new_sync(
+ |from| from.downcast::<#ty>().unwrap(),
+ |from| from.downcast::<#ty>().unwrap(),
+ |from| from.downcast::<#ty>().unwrap()
+ )
+ }
+ } else {
+ quote! {
+ syrette::libs::intertrait::Caster::<dyn #dst_trait>::new(
+ |from| from.downcast::<#ty>().unwrap(),
+ |from| from.downcast::<#ty>().unwrap(),
+ )
+ }
};
quote! {