fix clippy

This commit is contained in:
Evan Almloff 2023-08-08 13:43:57 -07:00
parent 4ee4cf23d3
commit 24c626b306
9 changed files with 30 additions and 27 deletions

View file

@ -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<Scheduler>) -> Rc<Self> {
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.

View file

@ -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),
};

View file

@ -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::<String>()
let mut result = String::new();
result += "#";
for c in c.iter() {
write!(string, "{c:02X?}").unwrap();
}
result
}
fn get_brightness(m: &Rc<MouseData>) -> i32 {

View file

@ -1,3 +1,5 @@
//! Tracked and computed state in Dioxus
use dioxus_core::{ScopeId, ScopeState};
use slab::Slab;
use std::{

View file

@ -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::*;

View file

@ -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<dyn Fn(&str) -> Result<UseEval, EvalError>>
})
}

View file

@ -446,7 +446,6 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
drop(tree);
children.reverse();
if let Some(node) = self.get_mut(id) {
let node = node;
f(node);
stack.extend(children.iter());
}

View file

@ -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
}

View file

@ -50,9 +50,11 @@ pub fn use_signal<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal<
#[derive(Clone)]
struct Unsubscriber {
scope: ScopeId,
subscribers: Rc<RefCell<Vec<Rc<RefCell<Vec<ScopeId>>>>>>,
subscribers: UnsubscriberArray,
}
type UnsubscriberArray = Rc<RefCell<Vec<Rc<RefCell<Vec<ScopeId>>>>>>;
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<Write<'a, O, I>> {
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<T> DerefMut for Write<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut *self.write
&mut self.write
}
}