From d083150e477211c7f97dfa44b837861206ccd05e Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Fri, 22 Dec 2023 21:11:55 -0500 Subject: [PATCH 1/2] Make IntoAttribute more flexible for Options --- integrations/axum/src/lib.rs | 8 +- .../src/macro_helpers/into_attribute.rs | 80 +------------------ leptos_dom/src/nonce.rs | 10 --- 3 files changed, 7 insertions(+), 91 deletions(-) diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 24eede3ad3..d3909e12e6 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -180,7 +180,7 @@ pub async fn generate_request_and_parts( /// /// This can then be set up at an appropriate route in your application: /// -/// ``` +/// ```rust,ignore /// use axum::{handler::Handler, routing::post, Router}; /// use leptos::*; /// use std::net::SocketAddr; @@ -416,7 +416,7 @@ pub type PinnedHtmlStream = /// includes everything described in the documentation for that function. /// /// This can then be set up at an appropriate route in your application: -/// ``` +/// ```rust,ignore /// use axum::{handler::Handler, Router}; /// use leptos::*; /// use leptos_config::get_configuration; @@ -516,7 +516,7 @@ where /// the documentation for that function. /// /// This can then be set up at an appropriate route in your application: -/// ``` +/// ```rust,ignore /// use axum::{handler::Handler, Router}; /// use leptos::*; /// use leptos_config::get_configuration; @@ -985,7 +985,7 @@ fn provide_contexts( /// the documentation for that function. /// /// This can then be set up at an appropriate route in your application: -/// ``` +/// ```rust,ignore /// use axum::{handler::Handler, Router}; /// use leptos::*; /// use leptos_config::get_configuration; diff --git a/leptos_dom/src/macro_helpers/into_attribute.rs b/leptos_dom/src/macro_helpers/into_attribute.rs index 18a8fa7c7e..18dc834291 100644 --- a/leptos_dom/src/macro_helpers/into_attribute.rs +++ b/leptos_dom/src/macro_helpers/into_attribute.rs @@ -138,15 +138,6 @@ macro_rules! impl_into_attr_boxed { }; } -impl IntoAttribute for Option { - #[inline(always)] - fn into_attribute(self) -> Attribute { - self.unwrap_or(Attribute::Option(None)) - } - - impl_into_attr_boxed! {} -} - impl IntoAttribute for String { #[inline(always)] fn into_attribute(self) -> Attribute { @@ -201,46 +192,10 @@ impl IntoAttribute for bool { impl_into_attr_boxed! {} } -impl IntoAttribute for Option { - #[inline(always)] - fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(Oco::Owned)) - } - - impl_into_attr_boxed! {} -} - -impl IntoAttribute for Option<&'static str> { - #[inline(always)] - fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(Oco::Borrowed)) - } - - impl_into_attr_boxed! {} -} - -impl IntoAttribute for Option> { +impl IntoAttribute for Option { #[inline(always)] fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(Oco::Counted)) - } - - impl_into_attr_boxed! {} -} - -impl IntoAttribute for Option> { - #[inline(always)] - fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(Oco::from)) - } - - impl_into_attr_boxed! {} -} - -impl IntoAttribute for Option> { - #[inline(always)] - fn into_attribute(self) -> Attribute { - Attribute::Option(self) + self.map_or(Attribute::Option(None), IntoAttribute::into_attribute) } impl_into_attr_boxed! {} @@ -310,17 +265,6 @@ macro_rules! attr_type { self.into_attribute() } } - - impl IntoAttribute for Option<$attr_type> { - fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(|n| n.to_string().into())) - } - - #[inline] - fn into_attribute_boxed(self: Box) -> Attribute { - self.into_attribute() - } - } }; } @@ -341,24 +285,6 @@ macro_rules! attr_signal_type { }; } -macro_rules! attr_signal_type_optional { - ($signal_type:ty) => { - #[cfg(not(feature = "nightly"))] - impl IntoAttribute for $signal_type - where - T: Clone, - Option: IntoAttribute, - { - fn into_attribute(self) -> Attribute { - let modified_fn = Rc::new(move || self.get().into_attribute()); - Attribute::Fn(modified_fn) - } - - impl_into_attr_boxed! {} - } - }; -} - attr_type!(&String); attr_type!(usize); attr_type!(u8); @@ -381,7 +307,7 @@ attr_signal_type!(RwSignal); attr_signal_type!(Memo); attr_signal_type!(Signal); attr_signal_type!(MaybeSignal); -attr_signal_type_optional!(MaybeProp); +attr_signal_type!(MaybeProp); #[cfg(all(target_arch = "wasm32", feature = "web"))] #[doc(hidden)] diff --git a/leptos_dom/src/nonce.rs b/leptos_dom/src/nonce.rs index 1969b68de0..68b7c0dbe6 100644 --- a/leptos_dom/src/nonce.rs +++ b/leptos_dom/src/nonce.rs @@ -69,16 +69,6 @@ impl IntoAttribute for Nonce { } } -impl IntoAttribute for Option { - fn into_attribute(self) -> Attribute { - Attribute::Option(self.map(|n| n.0.into())) - } - - fn into_attribute_boxed(self: Box) -> Attribute { - Attribute::Option(self.map(|n| n.0.into())) - } -} - /// Accesses the nonce that has been generated during the current /// server response. This can be added to inline `