浏览代码

chore: make clippy happier

Jonathan Kelley 3 年之前
父节点
当前提交
26ada2c7c1

+ 2 - 0
examples/borrowed.rs

@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
 /*
 /*
 Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
 Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
 to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.
 to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.

+ 3 - 3
examples/calculator.rs

@@ -98,7 +98,7 @@ fn app(cx: Scope) -> Element {
                                 button { class: "calculator-key key-0", onclick: move |_| input_digit(0),
                                 button { class: "calculator-key key-0", onclick: move |_| input_digit(0),
                                     "0"
                                     "0"
                                 }
                                 }
-                                button { class: "calculator-key key-dot", onclick: move |_| display_value.modify().push_str("."),
+                                button { class: "calculator-key key-dot", onclick: move |_| display_value.modify().push('.'),
                                     "●"
                                     "●"
                                 }
                                 }
                                 (1..10).map(|k| rsx!{
                                 (1..10).map(|k| rsx!{
@@ -175,7 +175,7 @@ fn calc_val(val: String) -> f64 {
 
 
     for c in val[start_index..].chars() {
     for c in val[start_index..].chars() {
         if c == '+' || c == '-' || c == '*' || c == '/' {
         if c == '+' || c == '-' || c == '*' || c == '/' {
-            if temp != "" {
+            if !temp.is_empty() {
                 match &operation as &str {
                 match &operation as &str {
                     "+" => result += temp.parse::<f64>().unwrap(),
                     "+" => result += temp.parse::<f64>().unwrap(),
                     "-" => result -= temp.parse::<f64>().unwrap(),
                     "-" => result -= temp.parse::<f64>().unwrap(),
@@ -191,7 +191,7 @@ fn calc_val(val: String) -> f64 {
         }
         }
     }
     }
 
 
-    if temp != "" {
+    if !temp.is_empty() {
         match &operation as &str {
         match &operation as &str {
             "+" => result += temp.parse::<f64>().unwrap(),
             "+" => result += temp.parse::<f64>().unwrap(),
             "-" => result -= temp.parse::<f64>().unwrap(),
             "-" => result -= temp.parse::<f64>().unwrap(),

+ 1 - 1
examples/crm.rs

@@ -1,7 +1,7 @@
 /*
 /*
 Tiny CRM: A port of the Yew CRM example to Dioxus.
 Tiny CRM: A port of the Yew CRM example to Dioxus.
 */
 */
-use dioxus::{events::FormEvent, prelude::*};
+use dioxus::prelude::*;
 
 
 fn main() {
 fn main() {
     dioxus::desktop::launch(app);
     dioxus::desktop::launch(app);

+ 3 - 2
examples/dog_app.rs

@@ -1,5 +1,6 @@
+#![allow(non_snake_case)]
+
 //! Render a bunch of doggos!
 //! Render a bunch of doggos!
-//!
 
 
 use std::collections::HashMap;
 use std::collections::HashMap;
 
 
@@ -50,7 +51,7 @@ fn app(cx: Scope) -> Element {
                 }
                 }
             }
             }
         }),
         }),
-        Some(Err(e)) => cx.render(rsx! {
+        Some(Err(_e)) => cx.render(rsx! {
             div { "Error fetching breeds" }
             div { "Error fetching breeds" }
         }),
         }),
         None => cx.render(rsx! {
         None => cx.render(rsx! {

+ 3 - 3
examples/file_explorer.rs

@@ -15,7 +15,7 @@ fn main() {
 }
 }
 
 
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
-    let files = use_ref(&cx, || Files::new());
+    let files = use_ref(&cx, Files::new);
 
 
     rsx!(cx, div {
     rsx!(cx, div {
         link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet", }
         link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet", }
@@ -28,8 +28,8 @@ fn app(cx: Scope) -> Element {
         }
         }
         main {
         main {
             files.read().path_names.iter().enumerate().map(|(dir_id, path)| {
             files.read().path_names.iter().enumerate().map(|(dir_id, path)| {
-                let path_end = path.split('/').last().unwrap_or(path.as_str());
-                let icon_type = if path_end.contains(".") {
+                let path_end = path.split('/').last().unwrap_or_else(|| path.as_str());
+                let icon_type = if path_end.contains('.') {
                     "description"
                     "description"
                 } else {
                 } else {
                     "folder"
                     "folder"

+ 1 - 1
examples/filedragdrop.rs

@@ -2,7 +2,7 @@ use dioxus::prelude::*;
 
 
 fn main() {
 fn main() {
     dioxus::desktop::launch_with_props(app, (), |c| {
     dioxus::desktop::launch_with_props(app, (), |c| {
-        c.with_file_drop_handler(|w, e| {
+        c.with_file_drop_handler(|_w, e| {
             println!("{:?}", e);
             println!("{:?}", e);
             false
             false
         })
         })

+ 3 - 1
examples/framework_benchmark.rs

@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
 use dioxus::prelude::*;
 use dioxus::prelude::*;
 use rand::prelude::*;
 use rand::prelude::*;
 
 
@@ -30,7 +32,7 @@ impl Label {
 }
 }
 
 
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
-    let items = use_ref(&cx, || vec![]);
+    let items = use_ref(&cx, Vec::new);
     let selected = use_state(&cx, || None);
     let selected = use_state(&cx, || None);
 
 
     cx.render(rsx! {
     cx.render(rsx! {

+ 0 - 2
examples/inputs.rs

@@ -2,8 +2,6 @@
 //!
 //!
 //! There is some conversion happening when input types are checkbox/radio/select/textarea etc.
 //! There is some conversion happening when input types are checkbox/radio/select/textarea etc.
 
 
-use std::sync::Arc;
-
 use dioxus::{events::FormEvent, prelude::*};
 use dioxus::{events::FormEvent, prelude::*};
 
 
 fn main() {
 fn main() {

+ 7 - 5
examples/pattern_model.rs

@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
 //! Example: Calculator
 //! Example: Calculator
 //! -------------------
 //! -------------------
 //!
 //!
@@ -30,7 +32,7 @@ fn main() {
 }
 }
 
 
 fn app(cx: Scope) -> Element {
 fn app(cx: Scope) -> Element {
-    let state = use_ref(&cx, || Calculator::new());
+    let state = use_ref(&cx, Calculator::new);
 
 
     cx.render(rsx! {
     cx.render(rsx! {
         style { [include_str!("./assets/calculator.css")] }
         style { [include_str!("./assets/calculator.css")] }
@@ -171,8 +173,8 @@ impl Calculator {
         }
         }
     }
     }
     fn input_dot(&mut self) {
     fn input_dot(&mut self) {
-        if self.display_value.find(".").is_none() {
-            self.display_value.push_str(".");
+        if !self.display_value.contains('.') {
+            self.display_value.push('.');
         }
         }
     }
     }
     fn perform_operation(&mut self) {
     fn perform_operation(&mut self) {
@@ -190,8 +192,8 @@ impl Calculator {
         }
         }
     }
     }
     fn toggle_sign(&mut self) {
     fn toggle_sign(&mut self) {
-        if self.display_value.starts_with("-") {
-            self.display_value = self.display_value.trim_start_matches("-").to_string();
+        if self.display_value.starts_with('-') {
+            self.display_value = self.display_value.trim_start_matches('-').to_string();
         } else {
         } else {
             self.display_value = format!("-{}", self.display_value);
             self.display_value = format!("-{}", self.display_value);
         }
         }

+ 10 - 2
examples/router.rs

@@ -19,7 +19,7 @@ fn app(cx: Scope) -> Element {
             Route { to: "/", "Home" }
             Route { to: "/", "Home" }
             Route { to: "users",
             Route { to: "users",
                 Route { to: "/", "User list" }
                 Route { to: "/", "User list" }
-                Route { to: ":name", BlogPost {} }
+                Route { to: ":name", User {} }
              }
              }
             Route { to: "blog"
             Route { to: "blog"
                 Route { to: "/", "Blog list" }
                 Route { to: "/", "Blog list" }
@@ -48,12 +48,20 @@ struct Query {
 
 
 fn User(cx: Scope) -> Element {
 fn User(cx: Scope) -> Element {
     let post = dioxus::router::use_route(&cx).last_segment();
     let post = dioxus::router::use_route(&cx).last_segment();
-    let query = dioxus::router::use_route(&cx).query::<Query>();
+    let query = dioxus::router::use_route(&cx)
+        .query::<Query>()
+        .unwrap_or(Query { bold: false });
 
 
     cx.render(rsx! {
     cx.render(rsx! {
         div {
         div {
             h1 { "Reading blog post: {post}" }
             h1 { "Reading blog post: {post}" }
             p { "example blog post" }
             p { "example blog post" }
+            
+            if query.bold {
+                rsx!{ b { "bold" } }
+            } else {
+                rsx!{ i { "italic" } }
+            }
         }
         }
     })
     })
 }
 }

+ 2 - 0
examples/suspense.rs

@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
 //! Suspense in Dioxus
 //! Suspense in Dioxus
 //!
 //!
 //! Currently, `rsx!` does not accept futures as values. To achieve the functionality
 //! Currently, `rsx!` does not accept futures as values. To achieve the functionality

+ 2 - 0
examples/tailwind.rs

@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
 //! Example: Basic Tailwind usage
 //! Example: Basic Tailwind usage
 //!
 //!
 //! This example shows how an app might be styled with TailwindCSS.
 //! This example shows how an app might be styled with TailwindCSS.

+ 5 - 6
examples/tasks.rs

@@ -13,13 +13,12 @@ fn app(cx: Scope) -> Element {
     let count = use_state(&cx, || 0);
     let count = use_state(&cx, || 0);
 
 
     use_future(&cx, move || {
     use_future(&cx, move || {
-        let count = UseState::for_async(&count);
-        // for_async![count];
+        let mut count = count.for_async();
         async move {
         async move {
-            // loop {
-            //     tokio::time::sleep(Duration::from_millis(1000)).await;
-            //     count += 1;
-            // }
+            loop {
+                tokio::time::sleep(Duration::from_millis(1000)).await;
+                count += 1;
+            }
         }
         }
     });
     });
 
 

+ 13 - 15
examples/todomvc.rs

@@ -19,7 +19,7 @@ pub struct TodoItem {
 }
 }
 
 
 pub fn app(cx: Scope<()>) -> Element {
 pub fn app(cx: Scope<()>) -> Element {
-    let todos = use_state(&cx, || im_rc::HashMap::<u32, TodoItem>::default());
+    let todos = use_state(&cx, im_rc::HashMap::<u32, TodoItem>::default);
     let filter = use_state(&cx, || FilterState::All);
     let filter = use_state(&cx, || FilterState::All);
     let draft = use_state(&cx, || "".to_string());
     let draft = use_state(&cx, || "".to_string());
     let mut todo_id = use_state(&cx, || 0);
     let mut todo_id = use_state(&cx, || 0);
@@ -56,19 +56,17 @@ pub fn app(cx: Scope<()>) -> Element {
                         autofocus: "true",
                         autofocus: "true",
                         oninput: move |evt| draft.set(evt.value.clone()),
                         oninput: move |evt| draft.set(evt.value.clone()),
                         onkeydown: move |evt| {
                         onkeydown: move |evt| {
-                            if evt.key == "Enter" {
-                                if !draft.is_empty() {
-                                    todos.modify().insert(
-                                        *todo_id,
-                                        TodoItem {
-                                            id: *todo_id,
-                                            checked: false,
-                                            contents: draft.get().clone(),
-                                        },
-                                    );
-                                    todo_id += 1;
-                                    draft.set("".to_string());
-                                }
+                            if evt.key == "Enter" && !draft.is_empty() {
+                                todos.modify().insert(
+                                    *todo_id,
+                                    TodoItem {
+                                        id: *todo_id,
+                                        checked: false,
+                                        contents: draft.get().clone(),
+                                    },
+                                );
+                                todo_id += 1;
+                                draft.set("".to_string());
                             }
                             }
                         }
                         }
                     }
                     }
@@ -90,7 +88,7 @@ pub fn app(cx: Scope<()>) -> Element {
                         (show_clear_completed).then(|| rsx!(
                         (show_clear_completed).then(|| rsx!(
                             button {
                             button {
                                 class: "clear-completed",
                                 class: "clear-completed",
-                                onclick: move |_| todos.modify().retain(|_, todo| todo.checked == false),
+                                onclick: move |_| todos.modify().retain(|_, todo| !todo.checked),
                                 "Clear completed"
                                 "Clear completed"
                             }
                             }
                         ))
                         ))