From 24c626b30660c42c64b6ec4aa9e5f1c7faf0f6ab Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 8 Aug 2023 13:43:57 -0700 Subject: [PATCH] fix clippy --- packages/core/src/runtime.rs | 9 ++++----- packages/desktop/src/protocol.rs | 9 +++++++-- packages/dioxus-tui/examples/hover.rs | 8 +++++++- packages/hooks/src/computed.rs | 2 ++ packages/hooks/src/lib.rs | 3 +-- packages/html/src/eval.rs | 2 +- packages/native-core/src/real_dom.rs | 1 - packages/rsx/src/lib.rs | 10 ++-------- packages/signals/src/signal.rs | 13 ++++++------- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/packages/core/src/runtime.rs b/packages/core/src/runtime.rs index 256b46909..b2b535830 100644 --- a/packages/core/src/runtime.rs +++ b/packages/core/src/runtime.rs @@ -24,7 +24,7 @@ where { RUNTIMES.with(|stack| { let stack = stack.borrow(); - stack.last().map(|r| f(&**r)) + stack.last().map(|r| f(r)) }) } @@ -36,7 +36,7 @@ where with_runtime(|runtime| { runtime .current_scope_id() - .and_then(|scope| runtime.get_context(scope).map(|sc| f(&*sc))) + .and_then(|scope| runtime.get_context(scope).map(|sc| f(&sc))) }) .flatten() } @@ -52,7 +52,7 @@ pub(crate) struct Runtime { impl Runtime { pub(crate) fn new(scheduler: Rc) -> Rc { - let runtime = Rc::new(Self { + Rc::new(Self { scheduler, scope_contexts: Default::default(), @@ -60,8 +60,7 @@ impl Runtime { scope_stack: Default::default(), rendering: Cell::new(true), - }); - runtime + }) } /// Create a scope context. This slab is synchronized with the scope slab. diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index 89ce50a48..53652f82f 100644 --- a/packages/desktop/src/protocol.rs +++ b/packages/desktop/src/protocol.rs @@ -158,8 +158,13 @@ fn get_mime_from_path(trimmed: &Path) -> Result<&'static str> { } let res = match infer::get_from_path(trimmed)?.map(|f| f.mime_type()) { - Some(t) if t == "text/plain" => get_mime_by_ext(trimmed), - Some(f) => f, + Some(f) => { + if f == "text/plain" { + get_mime_by_ext(trimmed) + } else { + f + } + } None => get_mime_by_ext(trimmed), }; diff --git a/packages/dioxus-tui/examples/hover.rs b/packages/dioxus-tui/examples/hover.rs index 77770b46d..c8784a8bc 100644 --- a/packages/dioxus-tui/examples/hover.rs +++ b/packages/dioxus-tui/examples/hover.rs @@ -1,6 +1,7 @@ use dioxus::{events::MouseData, prelude::*}; use dioxus_core::Event; use std::convert::TryInto; +use std::fmt::Write; use std::rc::Rc; fn main() { @@ -9,7 +10,12 @@ fn main() { fn app(cx: Scope) -> Element { fn to_str(c: &[i32; 3]) -> String { - "#".to_string() + &c.iter().map(|c| format!("{c:02X?}")).collect::() + let mut result = String::new(); + result += "#"; + for c in c.iter() { + write!(string, "{c:02X?}").unwrap(); + } + result } fn get_brightness(m: &Rc) -> i32 { diff --git a/packages/hooks/src/computed.rs b/packages/hooks/src/computed.rs index 94011d37d..1fcad8bb0 100644 --- a/packages/hooks/src/computed.rs +++ b/packages/hooks/src/computed.rs @@ -1,3 +1,5 @@ +//! Tracked and computed state in Dioxus + use dioxus_core::{ScopeId, ScopeState}; use slab::Slab; use std::{ diff --git a/packages/hooks/src/lib.rs b/packages/hooks/src/lib.rs index 7e5798167..6d7ab6f53 100644 --- a/packages/hooks/src/lib.rs +++ b/packages/hooks/src/lib.rs @@ -52,8 +52,7 @@ macro_rules! to_owned { }; } -mod computed; -pub use computed::*; +pub mod computed; mod use_on_unmount; pub use use_on_unmount::*; diff --git a/packages/html/src/eval.rs b/packages/html/src/eval.rs index b39eef805..c90f5125b 100644 --- a/packages/html/src/eval.rs +++ b/packages/html/src/eval.rs @@ -42,7 +42,7 @@ pub fn use_eval(cx: &ScopeState) -> &EvalCreator { Rc::new(move |script: &str| { eval_provider .new_evaluator(script.to_string()) - .map(|evaluator| UseEval::new(evaluator)) + .map(UseEval::new) }) as Rc Result> }) } diff --git a/packages/native-core/src/real_dom.rs b/packages/native-core/src/real_dom.rs index 44c378ddf..b520b2de1 100644 --- a/packages/native-core/src/real_dom.rs +++ b/packages/native-core/src/real_dom.rs @@ -446,7 +446,6 @@ impl RealDom { drop(tree); children.reverse(); if let Some(node) = self.get_mut(id) { - let node = node; f(node); stack.extend(children.iter()); } diff --git a/packages/rsx/src/lib.rs b/packages/rsx/src/lib.rs index 1f01fcd72..783dd3322 100644 --- a/packages/rsx/src/lib.rs +++ b/packages/rsx/src/lib.rs @@ -288,10 +288,7 @@ impl DynamicMapping { let idx = self.last_attribute_idx; self.last_attribute_idx += 1; - self.attribute_to_idx - .entry(attr) - .or_insert_with(Vec::new) - .push(idx); + self.attribute_to_idx.entry(attr).or_default().push(idx); idx } @@ -300,10 +297,7 @@ impl DynamicMapping { let idx = self.last_element_idx; self.last_element_idx += 1; - self.node_to_idx - .entry(node) - .or_insert_with(Vec::new) - .push(idx); + self.node_to_idx.entry(node).or_default().push(idx); idx } diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index 2bac8e1ea..5d696ee17 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -50,9 +50,11 @@ pub fn use_signal(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal< #[derive(Clone)] struct Unsubscriber { scope: ScopeId, - subscribers: Rc>>>>>, + subscribers: UnsubscriberArray, } +type UnsubscriberArray = Rc>>>>>; + impl Drop for Unsubscriber { fn drop(&mut self) { for subscribers in self.subscribers.borrow().iter() { @@ -269,10 +271,7 @@ impl<'a, T: 'static, I: 'static> Write<'a, T, I> { ) -> Option> { let Self { write, signal } = myself; let write = RefMut::filter_map(write, f).ok(); - write.map(|write| Write { - write, - signal: signal, - }) + write.map(|write| Write { write, signal }) } } @@ -280,13 +279,13 @@ impl<'a, T: 'static> Deref for Write<'a, T> { type Target = T; fn deref(&self) -> &Self::Target { - &*self.write + &self.write } } impl DerefMut for Write<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { - &mut *self.write + &mut self.write } }