chore: A few clippy fixes

Nothing systeamatic, just a bunch of fixes I stumbled over
during unrelated work.

No behavior change is intended in here...
This commit is contained in:
Tobias Hunger 2025-05-07 11:09:32 +00:00 committed by Tobias Hunger
parent 6070324848
commit d0b58760d3
19 changed files with 53 additions and 60 deletions

View file

@ -60,7 +60,7 @@ impl JsComponentCompiler {
#[napi(setter)]
pub fn set_include_paths(&mut self, include_paths: Vec<String>) {
self.internal.set_include_paths(include_paths.iter().map(|p| PathBuf::from(p)).collect());
self.internal.set_include_paths(include_paths.iter().map(PathBuf::from).collect());
}
#[napi(getter)]
@ -137,7 +137,6 @@ impl JsComponentCompiler {
self.structs_and_enums
.iter()
.filter_map(|ty| convert_type(&env, ty))
.into_iter()
.collect::<HashMap<String, JsUnknown>>()
}
@ -165,7 +164,6 @@ impl JsComponentCompiler {
self.structs_and_enums
.iter()
.filter_map(|ty| convert_type(&env, ty))
.into_iter()
.collect::<HashMap<String, JsUnknown>>()
}

View file

@ -253,12 +253,12 @@ impl JsComponentInstance {
env: Env,
callback_name: &String,
arguments: Vec<JsUnknown>,
args: &Vec<Type>,
args: &[Type],
) -> Result<Vec<Value>> {
let count = args.len();
let args = arguments
.into_iter()
.zip(args.into_iter())
.zip(args)
.map(|(a, ty)| super::value::to_value(&env, a, ty))
.collect::<Result<Vec<_>, _>>()?;
if args.len() != count {
@ -381,7 +381,7 @@ pub struct RefCountedReference {
impl RefCountedReference {
pub fn new<T: NapiRaw>(env: &Env, value: T) -> Result<Self> {
Ok(Self { env: env.clone(), reference: env.create_reference(value)? })
Ok(Self { env: *env, reference: env.create_reference(value)? })
}
pub fn get<T: NapiValue>(&self) -> Result<T> {

View file

@ -109,7 +109,7 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
Type::Color => {
match unknown.get_type() {
Ok(ValueType::String) => {
return Ok(unknown.coerce_to_string().and_then(|str| string_to_brush(str))?);
return unknown.coerce_to_string().and_then(string_to_brush)
}
Ok(ValueType::Object) => {
if let Ok(rgb_color) = unknown.coerce_to_object() {
@ -125,7 +125,7 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
Type::Brush => {
match unknown.get_type() {
Ok(ValueType::String) => {
return Ok(unknown.coerce_to_string().and_then(|str| string_to_brush(str))?);
return unknown.coerce_to_string().and_then(string_to_brush);
}
Ok(ValueType::Object) => {
if let Ok(obj) = unknown.coerce_to_object() {
@ -277,7 +277,7 @@ pub fn to_value(env: &Env, unknown: JsUnknown, typ: &Type) -> Result<Value> {
| Type::InferredCallback
| Type::Function { .. }
| Type::Callback { .. }
| Type::ComponentFactory { .. }
| Type::ComponentFactory
| Type::Easing
| Type::PathData
| Type::LayoutCache
@ -292,7 +292,7 @@ fn string_to_brush(js_string: JsString) -> Result<Value> {
.parse::<css_color_parser2::Color>()
.map_err(|_| napi::Error::from_reason(format!("Could not convert {string} to Brush.")))?;
Ok(Value::Brush(Brush::from(Color::from_argb_u8((c.a * 255.) as u8, c.r, c.g, c.b)).into()))
Ok(Value::Brush(Brush::from(Color::from_argb_u8((c.a * 255.) as u8, c.r, c.g, c.b))))
}
fn brush_from_color(rgb_color: Object) -> Result<Value> {

View file

@ -36,11 +36,9 @@ pub fn process_events() -> napi::Result<ProcessEventsResult> {
b.process_events(std::time::Duration::ZERO, i_slint_core::InternalToken)
})
.map_err(|e| napi::Error::from_reason(e.to_string()))
.and_then(|result| {
Ok(match result {
core::ops::ControlFlow::Continue(()) => ProcessEventsResult::Continue,
core::ops::ControlFlow::Break(()) => ProcessEventsResult::Exited,
})
.map(|result| match result {
core::ops::ControlFlow::Continue(()) => ProcessEventsResult::Continue,
core::ops::ControlFlow::Break(()) => ProcessEventsResult::Exited,
})
}
@ -125,7 +123,7 @@ pub fn print_to_console(env: Env, function: &str, arguments: core::fmt::Argument
return;
};
if let Err(err) = log_fn.call(None, &vec![js_message.into_unknown()]) {
if let Err(err) = log_fn.call(None, &[js_message.into_unknown()]) {
eprintln!("Unable to invoke console.{function}: {err}");
}
}

View file

@ -41,7 +41,7 @@ pub(crate) fn js_into_rust_model(
})?;
Ok(Rc::new(JsModel {
shared_model_notify,
env: env.clone(),
env: *env,
js_impl: RefCountedReference::new(env, maybe_js_impl)?,
row_data_type: row_data_type.clone(),
})
@ -230,7 +230,7 @@ impl ReadOnlyRustModel {
pub fn into_js(self, env: &Env) -> Result<JsUnknown> {
let model = self.0.clone();
let iterator_env = env.clone();
let iterator_env = *env;
let mut obj = self.into_instance(*env)?.as_object(*env);