diff --git a/packages/config-macro/src/lib.rs b/packages/config-macro/src/lib.rs index 93cc7d9bd..0660539d2 100644 --- a/packages/config-macro/src/lib.rs +++ b/packages/config-macro/src/lib.rs @@ -6,137 +6,33 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; -#[proc_macro] -pub fn server_only(input: TokenStream) -> TokenStream { - if cfg!(any(feature = "ssr", feature = "liveview")) { - let input = TokenStream2::from(input); - quote! { - #input +macro_rules! define_config_macro { + ($name:ident if $($cfg:tt)+) => { + #[proc_macro] + pub fn $name(input: TokenStream) -> TokenStream { + if cfg!($($cfg)+) { + let input = TokenStream2::from(input); + quote! { + { + #input + } + } + } else { + quote! { + {} + } + } + .into() } - } else { - quote! { - {} - } - } - .into() + }; } -#[proc_macro] -pub fn client(input: TokenStream) -> TokenStream { - if cfg!(any(feature = "desktop", feature = "web")) { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn web(input: TokenStream) -> TokenStream { - if cfg!(feature = "web") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn desktop(input: TokenStream) -> TokenStream { - if cfg!(feature = "desktop") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn mobile(input: TokenStream) -> TokenStream { - if cfg!(feature = "mobile") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn fullstack(input: TokenStream) -> TokenStream { - if cfg!(feature = "fullstack") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn static_generation(input: TokenStream) -> TokenStream { - if cfg!(feature = "static-generation") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn ssr(input: TokenStream) -> TokenStream { - if cfg!(feature = "ssr") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} - -#[proc_macro] -pub fn liveview(input: TokenStream) -> TokenStream { - if cfg!(feature = "liveview") { - let input = TokenStream2::from(input); - quote! { - #input - } - } else { - quote! { - {} - } - } - .into() -} +define_config_macro!(server_only if any(feature = "ssr", feature = "liveview")); +define_config_macro!(client if any(feature = "desktop", feature = "web")); +define_config_macro!(web if feature = "web"); +define_config_macro!(desktop if feature = "desktop"); +define_config_macro!(mobile if feature = "mobile"); +define_config_macro!(fullstack if feature = "fullstack"); +define_config_macro!(static_generation if feature = "static-generation"); +define_config_macro!(ssr if feature = "ssr"); +define_config_macro!(liveview if feature = "liveview"); diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index 270351123..d3ddbea9f 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -433,8 +433,11 @@ impl std::ops::Deref for Callback { // The real closure that we will never use. &uninit_closure }, + #[allow(clippy::missing_transmute_annotations)] // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. - unsafe { std::mem::transmute(self) }, + unsafe { + std::mem::transmute(self) + }, ); // Cast the closure to a trait object. diff --git a/packages/hooks/src/use_callback.rs b/packages/hooks/src/use_callback.rs index 67c1496ca..dfb90429e 100644 --- a/packages/hooks/src/use_callback.rs +++ b/packages/hooks/src/use_callback.rs @@ -95,8 +95,11 @@ impl std::ops::Deref for UseCallback { // The real closure that we will never use. &uninit_closure }, + #[allow(clippy::missing_transmute_annotations)] // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. - unsafe { std::mem::transmute(self) }, + unsafe { + std::mem::transmute(self) + }, ); // Cast the closure to a trait object. diff --git a/packages/signals/src/read.rs b/packages/signals/src/read.rs index 97d4d0e5d..8c828ec9e 100644 --- a/packages/signals/src/read.rs +++ b/packages/signals/src/read.rs @@ -220,8 +220,11 @@ pub trait Readable { // The real closure that we will never use. &uninit_closure }, + #[allow(clippy::missing_transmute_annotations)] // We transmute self into a reference to the closure. This is safe because we know that the closure has the same memory layout as Self so &Closure == &Self. - unsafe { std::mem::transmute(self) }, + unsafe { + std::mem::transmute(self) + }, ); // Cast the closure to a trait object.