Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IntoAttribute more flexible for Options #2130

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading