From ee25c03e74a9809d19d6cb7a3f7e90f3d5fc031c Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 27 Sep 2023 10:13:45 -0500 Subject: [PATCH] fix some clippy lints --- examples/README.md | 1 - examples/spread.rs | 3 +-- packages/core-macro/src/props/mod.rs | 4 +++- packages/core/src/lib.rs | 10 +++++----- packages/core/src/nodes.rs | 13 ++++++++++++- packages/html-internal-macro/src/lib.rs | 2 +- packages/html/src/elements.rs | 2 +- packages/html/src/global_attributes.rs | 2 +- packages/rsx/src/attribute.rs | 2 +- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/examples/README.md b/examples/README.md index 93530ba30..a20ffe60e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -139,7 +139,6 @@ Missing Features Missing examples - Shared state - Root-less element groups -- Spread props - Custom elements - Component Children: Pass children into child components - Render To string: Render a mounted virtualdom to a string diff --git a/examples/spread.rs b/examples/spread.rs index 698713d51..dc6b7b01d 100644 --- a/examples/spread.rs +++ b/examples/spread.rs @@ -21,10 +21,9 @@ fn app(cx: Scope) -> Element { } fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> { - let attributes = &*cx.props.attributes; render! { audio { - ..attributes, + ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" } } diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index 6b5ad30f3..a0bbdd4e9 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -894,12 +894,14 @@ Finally, call `.build()` to create the instance of `{name}`. path.span(), ); quote! { + #[allow(dead_code, non_camel_case_types, missing_docs)] impl #impl_generics dioxus_elements::extensions::#marker_name < #extend_lifetime > for #builder_name < #( #ty_generics ),* > #where_clause {} } }); Ok(quote! { - impl #impl_generics ::dioxus::prelude::HasAttributesBox<#extend_lifetime> for #builder_name < #( #ty_generics ),* > #where_clause { + #[allow(dead_code, non_camel_case_types, missing_docs)] + impl #impl_generics ::dioxus::prelude::HasAttributes<#extend_lifetime> for #builder_name < #( #ty_generics ),* > #where_clause { fn push_attribute( mut self, name: &#extend_lifetime str, diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 5fb5d7ba3..e2f8e96c1 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -76,7 +76,7 @@ pub(crate) mod innerlude { pub use crate::innerlude::{ fc_to_builder, vdom_is_rendering, AnyValue, Attribute, AttributeType, AttributeValue, BorrowedAttributeValue, CapturedError, Component, DynamicNode, Element, ElementId, Event, - Fragment, HasAttributesBox, IntoDynNode, LazyNodes, MountedAttribute, Mutation, Mutations, + Fragment, HasAttributes, IntoDynNode, LazyNodes, MountedAttribute, Mutation, Mutations, Properties, RenderReturn, Scope, ScopeId, ScopeState, Scoped, TaskId, Template, TemplateAttribute, TemplateNode, VComponent, VNode, VPlaceholder, VText, VirtualDom, }; @@ -89,10 +89,10 @@ pub mod prelude { consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, has_context, provide_context, provide_context_to_scope, provide_root_context, push_future, remove_future, schedule_update_any, spawn, spawn_forever, suspend, throw, AnyValue, - Attribute, AttributeType, Component, Element, Event, EventHandler, Fragment, - HasAttributesBox, IntoAttributeValue, LazyNodes, MountedAttribute, Properties, Runtime, - RuntimeGuard, Scope, ScopeId, ScopeState, Scoped, TaskId, Template, TemplateAttribute, - TemplateNode, Throw, VNode, VirtualDom, + Attribute, AttributeType, Component, Element, Event, EventHandler, Fragment, HasAttributes, + IntoAttributeValue, LazyNodes, MountedAttribute, Properties, Runtime, RuntimeGuard, Scope, + ScopeId, ScopeState, Scoped, TaskId, Template, TemplateAttribute, TemplateNode, Throw, + VNode, VirtualDom, }; } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index d0d10062a..2665db5a3 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -414,6 +414,7 @@ pub enum TemplateAttribute<'a> { }, } +/// An attribute with information about its position in the DOM and the element it was mounted to #[derive(Debug)] pub struct MountedAttribute<'a> { pub(crate) ty: AttributeType<'a>, @@ -440,6 +441,12 @@ impl<'a> From<&'a [Attribute<'a>]> for MountedAttribute<'a> { } } +impl<'a> From<&'a Vec>> for MountedAttribute<'a> { + fn from(attr: &'a Vec>) -> Self { + attr.as_slice().into() + } +} + impl<'a> MountedAttribute<'a> { /// Get the type of this attribute pub fn attribute_type(&self) -> &AttributeType<'a> { @@ -487,8 +494,10 @@ impl<'a> Attribute<'a> { } } +/// The type of an attribute #[derive(Debug)] pub enum AttributeType<'a> { + /// A single attribute Single(Attribute<'a>), /// Many different attributes sorted by name Many(&'a [Attribute<'a>]), @@ -899,7 +908,9 @@ impl<'a, T: IntoAttributeValue<'a>> IntoAttributeValue<'a> for Option { } } -pub trait HasAttributesBox<'a> { +/// A trait for anything that has a dynamic list of attributes +pub trait HasAttributes<'a> { + /// Push an attribute onto the list of attributes fn push_attribute( self, name: &'a str, diff --git a/packages/html-internal-macro/src/lib.rs b/packages/html-internal-macro/src/lib.rs index 3de23f6d6..049b36469 100644 --- a/packages/html-internal-macro/src/lib.rs +++ b/packages/html-internal-macro/src/lib.rs @@ -68,7 +68,7 @@ impl ToTokens for ImplExtensionAttributes { } }); tokens.append_all(quote! { - pub trait #extension_name<'a>: HasAttributesBox<'a> + Sized { + pub trait #extension_name<'a>: HasAttributes<'a> + Sized { #(#impls)* } }); diff --git a/packages/html/src/elements.rs b/packages/html/src/elements.rs index a004f65a2..fe7447790 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -1,7 +1,7 @@ #![allow(non_upper_case_globals)] use dioxus_core::prelude::IntoAttributeValue; -use dioxus_core::HasAttributesBox; +use dioxus_core::HasAttributes; use dioxus_html_internal_macro::impl_extension_attributes; #[cfg(feature = "hot-reload-context")] use dioxus_rsx::HotReloadingContext; diff --git a/packages/html/src/global_attributes.rs b/packages/html/src/global_attributes.rs index 97811fe1f..41a57ab84 100644 --- a/packages/html/src/global_attributes.rs +++ b/packages/html/src/global_attributes.rs @@ -1,7 +1,7 @@ #![allow(non_upper_case_globals)] use dioxus_core::prelude::IntoAttributeValue; -use dioxus_core::HasAttributesBox; +use dioxus_core::HasAttributes; use dioxus_html_internal_macro::impl_extension_attributes; use crate::AttributeDiscription; diff --git a/packages/rsx/src/attribute.rs b/packages/rsx/src/attribute.rs index 6f5d0a096..76acc43bf 100644 --- a/packages/rsx/src/attribute.rs +++ b/packages/rsx/src/attribute.rs @@ -32,7 +32,7 @@ impl ToTokens for AttributeType { fn to_tokens(&self, tokens: &mut TokenStream2) { match self { AttributeType::Named(n) => tokens.append_all(quote! { #n }), - AttributeType::Spread(e) => tokens.append_all(quote! { #e.into() }), + AttributeType::Spread(e) => tokens.append_all(quote! { (&#e).into() }), } } }