Quellcode durchsuchen

fix some clippy lints

Evan Almloff vor 1 Jahr
Ursprung
Commit
ee25c03e74

+ 0 - 1
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

+ 1 - 2
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}"
         }
     }

+ 3 - 1
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,

+ 5 - 5
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,
     };
 }
 

+ 12 - 1
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<Attribute<'a>>> for MountedAttribute<'a> {
+    fn from(attr: &'a Vec<Attribute<'a>>) -> 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<T> {
     }
 }
 
-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,

+ 1 - 1
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)*
             }
         });

+ 1 - 1
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;

+ 1 - 1
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;

+ 1 - 1
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() }),
         }
     }
 }