aboutsummaryrefslogtreecommitdiff
path: root/syrette_macros/src/libs/intertrait_macros/gen_caster.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-18 20:48:41 +0200
committerHampusM <hampus@hampusmat.com>2022-07-18 20:49:33 +0200
commit8976c166cff4c98c43cdc409275f548eb27ecb13 (patch)
treef072980e77e12a85aac7282b89d3114cf69864a7 /syrette_macros/src/libs/intertrait_macros/gen_caster.rs
parent51e8d04c2299e6468213d8ee4f9e15d783094379 (diff)
refactor: reduce the capabilities of the castable_to macro
Diffstat (limited to 'syrette_macros/src/libs/intertrait_macros/gen_caster.rs')
-rw-r--r--syrette_macros/src/libs/intertrait_macros/gen_caster.rs34
1 files changed, 10 insertions, 24 deletions
diff --git a/syrette_macros/src/libs/intertrait_macros/gen_caster.rs b/syrette_macros/src/libs/intertrait_macros/gen_caster.rs
index 268fb09..a0e63b5 100644
--- a/syrette_macros/src/libs/intertrait_macros/gen_caster.rs
+++ b/syrette_macros/src/libs/intertrait_macros/gen_caster.rs
@@ -20,33 +20,19 @@ use quote::ToTokens;
use uuid::adapter::Simple;
use uuid::Uuid;
-pub fn generate_caster(
- ty: &impl ToTokens,
- trait_: &impl ToTokens,
- sync: bool,
-) -> TokenStream
+pub fn generate_caster(ty: &impl ToTokens, trait_: &impl ToTokens) -> TokenStream
{
let mut fn_buf = [0u8; FN_BUF_LEN];
+
let fn_ident = format_ident!("{}", new_fn_name(&mut fn_buf));
- let new_caster = if sync {
- quote! {
- syrette::libs::intertrait::Caster::<dyn #trait_>::new_sync(
- |from| from.downcast_ref::<#ty>().unwrap(),
- |from| from.downcast_mut::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap()
- )
- }
- } else {
- quote! {
- syrette::libs::intertrait::Caster::<dyn #trait_>::new(
- |from| from.downcast_ref::<#ty>().unwrap(),
- |from| from.downcast_mut::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap(),
- |from| from.downcast::<#ty>().unwrap(),
- )
- }
+
+ let new_caster = quote! {
+ syrette::libs::intertrait::Caster::<dyn #trait_>::new(
+ |from| from.downcast_ref::<#ty>().unwrap(),
+ |from| from.downcast_mut::<#ty>().unwrap(),
+ |from| from.downcast::<#ty>().unwrap(),
+ |from| from.downcast::<#ty>().unwrap(),
+ )
};
quote! {