Merge pull request #154 from DioxusLabs/jk/quiet-clippy-examples
Make clippy happier on the examples.
This commit is contained in:
14 files changed
+55
-41
No files matched your search
@@ -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.
|
||||||
|
|||||||
@@ -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
@@ -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
@@ -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! {
|
||||||
|
|||||||
@@ -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 path_end = path.split('/').last().unwrap_or_else(|| path.as_str());
|
||||||
let icon_type = if path_end.contains(".") {
|
let icon_type = if path_end.contains('.') {
|
||||||
"description"
|
"description"
|
||||||
} else {
|
} else {
|
||||||
"folder"
|
"folder"
|
||||||
|
|||||||
@@ -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
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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! {
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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() {
|
if !self.display_value.contains('.') {
|
||||||
self.display_value.push_str(".");
|
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("-") {
|
if self.display_value.starts_with('-') {
|
||||||
self.display_value = self.display_value.trim_start_matches("-").to_string();
|
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
@@ -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" } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
@@ -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);
|
let mut count = count.for_async();
|
||||||
// for_async![count];
|
|
||||||
async move {
|
async move {
|
||||||
// loop {
|
loop {
|
||||||
// tokio::time::sleep(Duration::from_millis(1000)).await;
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||||
// count += 1;
|
count += 1;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+13
-15
@@ -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 evt.key == "Enter" && !draft.is_empty() {
|
||||||
if !draft.is_empty() {
|
todos.modify().insert(
|
||||||
todos.modify().insert(
|
*todo_id,
|
||||||
*todo_id,
|
TodoItem {
|
||||||
TodoItem {
|
id: *todo_id,
|
||||||
id: *todo_id,
|
checked: false,
|
||||||
checked: false,
|
contents: draft.get().clone(),
|
||||||
contents: draft.get().clone(),
|
},
|
||||||
},
|
);
|
||||||
);
|
todo_id += 1;
|
||||||
todo_id += 1;
|
draft.set("".to_string());
|
||||||
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"
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in new issue
Block a user