diff --git a/examples/borrowed.rs b/examples/borrowed.rs index 63191bc97..815d6ceed 100644 --- a/examples/borrowed.rs +++ b/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 to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T. diff --git a/examples/calculator.rs b/examples/calculator.rs index a849833a3..8597a8897 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -98,7 +98,7 @@ fn app(cx: Scope) -> Element { button { class: "calculator-key key-0", onclick: move |_| input_digit(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!{ @@ -175,7 +175,7 @@ fn calc_val(val: String) -> f64 { for c in val[start_index..].chars() { if c == '+' || c == '-' || c == '*' || c == '/' { - if temp != "" { + if !temp.is_empty() { match &operation as &str { "+" => result += temp.parse::().unwrap(), "-" => result -= temp.parse::().unwrap(), @@ -191,7 +191,7 @@ fn calc_val(val: String) -> f64 { } } - if temp != "" { + if !temp.is_empty() { match &operation as &str { "+" => result += temp.parse::().unwrap(), "-" => result -= temp.parse::().unwrap(), diff --git a/examples/crm.rs b/examples/crm.rs index d4f3d1579..504459fc7 100644 --- a/examples/crm.rs +++ b/examples/crm.rs @@ -1,7 +1,7 @@ /* Tiny CRM: A port of the Yew CRM example to Dioxus. */ -use dioxus::{events::FormEvent, prelude::*}; +use dioxus::prelude::*; fn main() { dioxus::desktop::launch(app); diff --git a/examples/dog_app.rs b/examples/dog_app.rs index b2f8429ee..f2c51d6fb 100644 --- a/examples/dog_app.rs +++ b/examples/dog_app.rs @@ -1,5 +1,6 @@ +#![allow(non_snake_case)] + //! Render a bunch of doggos! -//! 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" } }), None => cx.render(rsx! { diff --git a/examples/file_explorer.rs b/examples/file_explorer.rs index 5d4bf8be8..fe5ab23bb 100644 --- a/examples/file_explorer.rs +++ b/examples/file_explorer.rs @@ -15,7 +15,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let files = use_ref(&cx, || Files::new()); + let files = use_ref(&cx, Files::new); rsx!(cx, div { link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet", } @@ -28,8 +28,8 @@ fn app(cx: Scope) -> Element { } main { 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" } else { "folder" diff --git a/examples/filedragdrop.rs b/examples/filedragdrop.rs index a36b64ddb..523405b39 100644 --- a/examples/filedragdrop.rs +++ b/examples/filedragdrop.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { dioxus::desktop::launch_with_props(app, (), |c| { - c.with_file_drop_handler(|w, e| { + c.with_file_drop_handler(|_w, e| { println!("{:?}", e); false }) diff --git a/examples/framework_benchmark.rs b/examples/framework_benchmark.rs index 0a70bd25b..69e3b8faa 100644 --- a/examples/framework_benchmark.rs +++ b/examples/framework_benchmark.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + use dioxus::prelude::*; use rand::prelude::*; @@ -30,7 +32,7 @@ impl Label { } fn app(cx: Scope) -> Element { - let items = use_ref(&cx, || vec![]); + let items = use_ref(&cx, Vec::new); let selected = use_state(&cx, || None); cx.render(rsx! { diff --git a/examples/inputs.rs b/examples/inputs.rs index 11334b59a..5e0a52244 100644 --- a/examples/inputs.rs +++ b/examples/inputs.rs @@ -2,8 +2,6 @@ //! //! There is some conversion happening when input types are checkbox/radio/select/textarea etc. -use std::sync::Arc; - use dioxus::{events::FormEvent, prelude::*}; fn main() { diff --git a/examples/pattern_model.rs b/examples/pattern_model.rs index c679d1427..a7b821750 100644 --- a/examples/pattern_model.rs +++ b/examples/pattern_model.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + //! Example: Calculator //! ------------------- //! @@ -30,7 +32,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let state = use_ref(&cx, || Calculator::new()); + let state = use_ref(&cx, Calculator::new); cx.render(rsx! { style { [include_str!("./assets/calculator.css")] } @@ -171,8 +173,8 @@ impl Calculator { } } 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) { @@ -190,8 +192,8 @@ impl Calculator { } } 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 { self.display_value = format!("-{}", self.display_value); } diff --git a/examples/router.rs b/examples/router.rs index 121514423..f34676ab7 100644 --- a/examples/router.rs +++ b/examples/router.rs @@ -19,7 +19,7 @@ fn app(cx: Scope) -> Element { Route { to: "/", "Home" } Route { to: "users", Route { to: "/", "User list" } - Route { to: ":name", BlogPost {} } + Route { to: ":name", User {} } } Route { to: "blog" Route { to: "/", "Blog list" } @@ -48,12 +48,20 @@ struct Query { fn User(cx: Scope) -> Element { let post = dioxus::router::use_route(&cx).last_segment(); - let query = dioxus::router::use_route(&cx).query::(); + let query = dioxus::router::use_route(&cx) + .query::() + .unwrap_or(Query { bold: false }); cx.render(rsx! { div { h1 { "Reading blog post: {post}" } p { "example blog post" } + + if query.bold { + rsx!{ b { "bold" } } + } else { + rsx!{ i { "italic" } } + } } }) } diff --git a/examples/suspense.rs b/examples/suspense.rs index 881d6cae7..5a9bf4fd8 100644 --- a/examples/suspense.rs +++ b/examples/suspense.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + //! Suspense in Dioxus //! //! Currently, `rsx!` does not accept futures as values. To achieve the functionality diff --git a/examples/tailwind.rs b/examples/tailwind.rs index cbefd248f..6611fc47b 100644 --- a/examples/tailwind.rs +++ b/examples/tailwind.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + //! Example: Basic Tailwind usage //! //! This example shows how an app might be styled with TailwindCSS. diff --git a/examples/tasks.rs b/examples/tasks.rs index a0ab7675c..f71abe38d 100644 --- a/examples/tasks.rs +++ b/examples/tasks.rs @@ -13,13 +13,12 @@ fn app(cx: Scope) -> Element { let count = use_state(&cx, || 0); use_future(&cx, move || { - let count = UseState::for_async(&count); - // for_async![count]; + let mut count = count.for_async(); async move { - // loop { - // tokio::time::sleep(Duration::from_millis(1000)).await; - // count += 1; - // } + loop { + tokio::time::sleep(Duration::from_millis(1000)).await; + count += 1; + } } }); diff --git a/examples/todomvc.rs b/examples/todomvc.rs index 8adb01d34..6daddbf20 100644 --- a/examples/todomvc.rs +++ b/examples/todomvc.rs @@ -19,7 +19,7 @@ pub struct TodoItem { } pub fn app(cx: Scope<()>) -> Element { - let todos = use_state(&cx, || im_rc::HashMap::::default()); + let todos = use_state(&cx, im_rc::HashMap::::default); let filter = use_state(&cx, || FilterState::All); let draft = use_state(&cx, || "".to_string()); let mut todo_id = use_state(&cx, || 0); @@ -56,19 +56,17 @@ pub fn app(cx: Scope<()>) -> Element { autofocus: "true", oninput: move |evt| draft.set(evt.value.clone()), 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!( button { class: "clear-completed", - onclick: move |_| todos.modify().retain(|_, todo| todo.checked == false), + onclick: move |_| todos.modify().retain(|_, todo| !todo.checked), "Clear completed" } ))