Skip to content

Commit

Permalink
feat: make IntoAttribute more flexible for `Option<T: IntoAttribute…
Browse files Browse the repository at this point in the history
…>` (#2130)
  • Loading branch information
SleeplessOne1917 authored Dec 30, 2023
1 parent da533ad commit 16cf3c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 87 deletions.
80 changes: 3 additions & 77 deletions leptos_dom/src/macro_helpers/into_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ macro_rules! impl_into_attr_boxed {
};
}

impl IntoAttribute for Option<Attribute> {
#[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 {
Expand Down Expand Up @@ -201,46 +192,10 @@ impl IntoAttribute for bool {
impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<String> {
#[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<Rc<str>> {
impl<T: IntoAttribute> IntoAttribute for Option<T> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::Counted))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<Cow<'static, str>> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::from))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<Oco<'static, str>> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self)
self.map_or(Attribute::Option(None), IntoAttribute::into_attribute)
}

impl_into_attr_boxed! {}
Expand Down Expand Up @@ -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<Self>) -> Attribute {
self.into_attribute()
}
}
};
}

Expand All @@ -341,24 +285,6 @@ macro_rules! attr_signal_type {
};
}

macro_rules! attr_signal_type_optional {
($signal_type:ty) => {
#[cfg(not(feature = "nightly"))]
impl<T> IntoAttribute for $signal_type
where
T: Clone,
Option<T>: 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);
Expand All @@ -381,7 +307,7 @@ attr_signal_type!(RwSignal<T>);
attr_signal_type!(Memo<T>);
attr_signal_type!(Signal<T>);
attr_signal_type!(MaybeSignal<T>);
attr_signal_type_optional!(MaybeProp<T>);
attr_signal_type!(MaybeProp<T>);

#[cfg(all(target_arch = "wasm32", feature = "web"))]
#[doc(hidden)]
Expand Down
10 changes: 0 additions & 10 deletions leptos_dom/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ impl IntoAttribute for Nonce {
}
}

impl IntoAttribute for Option<Nonce> {
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(|n| n.0.into()))
}

fn into_attribute_boxed(self: Box<Self>) -> 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 `<script>` and
/// `<style>` tags for compatibility with a Content Security Policy.
Expand Down

0 comments on commit 16cf3c4

Please sign in to comment.