From cdd1dc1964cecdf8fd9d8bd9841aaadcc3e14575 Mon Sep 17 00:00:00 2001 From: Geoffrey Mureithi Date: Sat, 1 Oct 2022 20:54:28 +0300 Subject: [PATCH] Clippy fixes + Bump up version --- Cargo.lock | 8 ++++---- Cargo.toml | 8 ++++---- crates/hirola-core/Cargo.toml | 4 ++-- crates/hirola-core/src/callback.rs | 11 ++++++----- crates/hirola-core/src/mixins.rs | 9 +++++---- crates/hirola-core/src/reactive/signal.rs | 2 +- crates/hirola-form/Cargo.toml | 4 ++-- crates/hirola-macros/Cargo.toml | 2 +- crates/hirola-macros/src/component.rs | 4 ++-- crates/hirola-macros/src/lib.rs | 8 ++++---- 10 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6863969..947c3d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,7 @@ dependencies = [ [[package]] name = "hirola" -version = "0.2.0-beta.1" +version = "0.2.0" dependencies = [ "document-features", "hirola", @@ -341,7 +341,7 @@ dependencies = [ [[package]] name = "hirola-core" -version = "0.2.0-beta.1" +version = "0.2.0" dependencies = [ "anyhow", "anymap", @@ -363,7 +363,7 @@ dependencies = [ [[package]] name = "hirola-form" -version = "0.2.0-beta.1" +version = "0.2.0" dependencies = [ "hirola-core", "json_dotpath", @@ -377,7 +377,7 @@ dependencies = [ [[package]] name = "hirola-macros" -version = "0.2.0-beta.1" +version = "0.2.0" dependencies = [ "hirola-core", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index e2a69d1..0af6487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hirola" -version = "0.2.0-beta.1" +version = "0.2.0" authors = ["Geoffrey Mureithi "] description = "Hirola is an un-opinionated web framework that is focused on simplicity and predictability" repository = "https://github.com/geofmureithi/hirola" @@ -11,9 +11,9 @@ keywords = ["wasm", "html", "dom", "web"] edition = "2021" [dependencies] -hirola-core = { path = "crates/hirola-core", version = "0.2.0-beta.1" } -hirola-macros = { path = "crates/hirola-macros", version = "0.2.0-beta.1" } -hirola-form = { path = "crates/hirola-form", version = "0.2.0-beta.1", optional = true } +hirola-core = { path = "crates/hirola-core", version = "0.2.0" } +hirola-macros = { path = "crates/hirola-macros", version = "0.2.0" } +hirola-form = { path = "crates/hirola-form", version = "0.2.0", optional = true } [features] diff --git a/crates/hirola-core/Cargo.toml b/crates/hirola-core/Cargo.toml index 91bb9f5..0b12d78 100644 --- a/crates/hirola-core/Cargo.toml +++ b/crates/hirola-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hirola-core" -version = "0.2.0-beta.1" +version = "0.2.0" authors = ["Geoffrey Mureithi "] edition = "2021" description = "An html library for building client side webapps" @@ -18,7 +18,7 @@ chrono = { version = "0.4", features = ["wasmbind"] } anyhow = "1.0" thiserror = "1.0" html-escape = { version = "0.2.7", optional = true } -hirola-macros = { path = "../hirola-macros", version = "0.2.0-beta.1" } +hirola-macros = { path = "../hirola-macros", version = "0.2.0" } ref-cast = "1.0" serde = { version = "1.0", optional = true } wasm-bindgen = { version = "0.2", optional = true } diff --git a/crates/hirola-core/src/callback.rs b/crates/hirola-core/src/callback.rs index 629de89..d76e699 100644 --- a/crates/hirola-core/src/callback.rs +++ b/crates/hirola-core/src/callback.rs @@ -1,7 +1,7 @@ use crate::prelude::DomNode; pub trait StateReduce { - fn mut_callback(&self, f: F) -> Box ()> + fn mut_callback(&self, f: F) -> Box where F: Fn(&T, E) -> T + 'static; } @@ -22,18 +22,19 @@ pub trait Mixin { impl Mixin for T where - T: Fn(DomNode) -> (), + T: Fn(DomNode), { fn mixin(&self, _ns: &str, node: DomNode) -> Result<(), MixinError> { - Ok((&self)(node)) + (&self)(node); + Ok(()) } } pub trait State: Clone { // Get a callback that allows interacting with state - fn callback(&self, f: F) -> Box ()> + fn callback(&self, f: F) -> Box where - F: Fn(&Self, E) -> () + 'static, + F: Fn(&Self, E) + 'static, Self: 'static, { let state = self.clone(); diff --git a/crates/hirola-core/src/mixins.rs b/crates/hirola-core/src/mixins.rs index 1b01484..447c3eb 100644 --- a/crates/hirola-core/src/mixins.rs +++ b/crates/hirola-core/src/mixins.rs @@ -67,13 +67,13 @@ use crate::{ pub fn rhtml<'a>(text: &'a str) -> Box () + 'a> { let cb = move |node: DomNode| { let element = node.unchecked_into::(); - element.set_inner_html(&format!("{text}")); + element.set_inner_html(text); }; Box::new(cb) } /// A mixin that allows adding nonsignal text -pub fn rtext<'a, D: Display>(text: &'a D) -> Box () + 'a> { +pub fn rtext<'a, D: Display>(text: &'a D) -> Box { let cb = move |node: DomNode| { let element = node.unchecked_into::(); element.set_text_content(Some(&format!("{text}"))); @@ -82,7 +82,7 @@ pub fn rtext<'a, D: Display>(text: &'a D) -> Box () + 'a> { } /// Mixin that adds text to a dom node -pub fn text(text: &Signal) -> Box ()> { +pub fn text(text: &Signal) -> Box { let signal = text.clone(); let cb = move |node: DomNode| { let element = node.unchecked_into::(); @@ -96,7 +96,7 @@ pub fn text(text: &Signal) -> Box ()> { } /// Mixin that adds text to a dom node -pub fn show(shown: &Signal) -> Box ()> { +pub fn show(shown: &Signal) -> Box { let signal = shown.clone(); let cb = move |node: DomNode| { let element = node.unchecked_into::(); @@ -158,6 +158,7 @@ where /// Two way binding for input and signals pub mod model { use super::*; + /// Bind a [HtmlInputElement] to a [Signal] pub fn input(s: &Signal) -> Model { Model(s.clone(), PhantomData) } diff --git a/crates/hirola-core/src/reactive/signal.rs b/crates/hirola-core/src/reactive/signal.rs index de1c3d6..1f6e276 100644 --- a/crates/hirola-core/src/reactive/signal.rs +++ b/crates/hirola-core/src/reactive/signal.rs @@ -225,7 +225,7 @@ impl Signal { impl StateReduce for Signal { /// Sets the return value - fn mut_callback(&self, f: F) -> Box ()> + fn mut_callback(&self, f: F) -> Box where F: Fn(&T, E) -> T + 'static, { diff --git a/crates/hirola-form/Cargo.toml b/crates/hirola-form/Cargo.toml index 684cca2..a0395a7 100644 --- a/crates/hirola-form/Cargo.toml +++ b/crates/hirola-form/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hirola-form" -version = "0.2.0-beta.1" +version = "0.2.0" edition = "2021" description = "Form mixins and utilities for hirola" repository = "https://github.com/geofmureithi/hirola" @@ -12,7 +12,7 @@ keywords = ["wasm", "html", "form", "web"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -hirola-core = { path = "../hirola-core", version = "0.2.0-beta.1", features=["serde"] } +hirola-core = { path = "../hirola-core", version = "0.2.0", features=["serde"] } wasm-bindgen = {version = "0.2", features= ["serde-serialize"]} validator = "0.10" validator_derive = "0.10" diff --git a/crates/hirola-macros/Cargo.toml b/crates/hirola-macros/Cargo.toml index caeb493..8fe327b 100644 --- a/crates/hirola-macros/Cargo.toml +++ b/crates/hirola-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hirola-macros" -version = "0.2.0-beta.1" +version = "0.2.0" authors = ["Geoffrey Mureithi "] edition = "2021" description = "Hirola is an un-opinionated web framework that is focused on simplicity and predictability" diff --git a/crates/hirola-macros/src/component.rs b/crates/hirola-macros/src/component.rs index 68a43cf..33c726b 100644 --- a/crates/hirola-macros/src/component.rs +++ b/crates/hirola-macros/src/component.rs @@ -12,7 +12,7 @@ pub fn create_function_component(f: syn::ItemFn) -> TokenStream { let block = f.block; let vis = f.vis; - let inputs_block = if inputs.len() > 0 { + let inputs_block = if !inputs.is_empty() { let input_names: Vec<_> = inputs.iter().collect(); quote!({ #(#vis #input_names),* }) @@ -20,7 +20,7 @@ pub fn create_function_component(f: syn::ItemFn) -> TokenStream { quote!(;) }; - let inputs_reading = if inputs.len() == 0 { + let inputs_reading = if inputs.is_empty() { quote!() } else { let input_names: Vec<_> = inputs diff --git a/crates/hirola-macros/src/lib.rs b/crates/hirola-macros/src/lib.rs index 0db6c6c..ff14efe 100644 --- a/crates/hirola-macros/src/lib.rs +++ b/crates/hirola-macros/src/lib.rs @@ -41,11 +41,11 @@ fn node_to_tokens(node: Node) -> TokenStream { let name = node.name_as_string(); if let Some(name) = name { - if &name[0..1].to_lowercase() == &name[0..1] { + if name[0..1].to_lowercase() == name[0..1] { let attributes = node .attributes .iter() - .map(|attribute| attribute_to_tokens(attribute)); + .map(attribute_to_tokens); let children_tokens = children_to_tokens(node.children); @@ -76,7 +76,7 @@ fn node_to_tokens(node: Node) -> TokenStream { None => quote! {}, }) .collect::>(); - if node.children.len() > 0 { + if !node.children.is_empty() { let children_tokens = children_to_tokens(node.children); attributes.extend(vec![quote! { children: { @@ -87,7 +87,7 @@ fn node_to_tokens(node: Node) -> TokenStream { }]); } - let quoted = if attributes.len() == 0 { + let quoted = if attributes.is_empty() { quote!({&#fnname }) } else { quote!({ &#fnname {#(#attributes),*} })