From 72afe790fd1390a5eb92b004a31e1a7005462ce5 Mon Sep 17 00:00:00 2001 From: Breadway Date: Thu, 6 Aug 2026 08:46:41 +0800 Subject: [PATCH] Fix clippy warnings across workspace - io.rs: factor the pending-RPC-replies map into a PendingReplies type alias (type_complexity) - lua_env.rs: drop a redundant i64->i64 cast and an unneeded borrow before create_string (unnecessary_cast, needless_borrows_for_generic_args) - state_engine.rs: iterate watches.values() instead of discarding the key from watches.iter() (for_kv_map) - module_host_sandbox.rs: collapse nested if into a single condition (collapsible_if) (cherry picked from commit 49063cb98ddfeae35d842a6cf439123cfda763d9) --- bread-module-host/src/io.rs | 7 +++++-- bread-module-host/src/lua_env.rs | 4 ++-- breadd/src/core/state_engine.rs | 2 +- breadd/tests/module_host_sandbox.rs | 6 ++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bread-module-host/src/io.rs b/bread-module-host/src/io.rs index 7014a16..96c1d42 100644 --- a/bread-module-host/src/io.rs +++ b/bread-module-host/src/io.rs @@ -33,6 +33,10 @@ pub enum IoCommand { }, } +/// In-flight RPC calls awaiting a response, keyed by request id: each entry +/// is the reply channel for the call that's blocked waiting on it. +type PendingReplies = Arc>>>>; + /// Something the IO thread has for the Lua-driving thread: either an /// unsolicited push (a subscribed event fired, a timer fired) or "the /// connection is gone" (breadd exited, socket closed, etc). @@ -148,8 +152,7 @@ pub fn run( // Lua-side call is blocked waiting for them; a dedicated thread // bridges the synchronous `cmd_rx` (fed from the Lua thread) onto an // async channel this task can select on. - let pending: Arc>>>> = - Arc::new(Mutex::new(HashMap::new())); + let pending: PendingReplies = Arc::new(Mutex::new(HashMap::new())); let (async_cmd_tx, mut async_cmd_rx) = tokio::sync::mpsc::unbounded_channel::(); std::thread::spawn(move || { diff --git a/bread-module-host/src/lua_env.rs b/bread-module-host/src/lua_env.rs index 3439f61..cfaab0d 100644 --- a/bread-module-host/src/lua_env.rs +++ b/bread-module-host/src/lua_env.rs @@ -93,7 +93,7 @@ fn json_to_lua<'lua>(lua: &'lua Lua, value: &JsonValue) -> mlua::Result LuaValue::Boolean(*b), JsonValue::Number(n) => { if let Some(i) = n.as_i64() { - LuaValue::Integer(i as i64) + LuaValue::Integer(i) } else { LuaValue::Number(n.as_f64().unwrap_or(0.0)) } @@ -243,7 +243,7 @@ impl ModuleHostLua { let decode_fn = lua.create_function(|lua, s: String| { match serde_json::from_str::(&s) { Ok(v) => Ok((json_to_lua(lua, &v)?, LuaValue::Nil)), - Err(e) => Ok((LuaValue::Nil, LuaValue::String(lua.create_string(&e.to_string())?))), + Err(e) => Ok((LuaValue::Nil, LuaValue::String(lua.create_string(e.to_string())?))), } })?; json_tbl.set("decode", decode_fn)?; diff --git a/breadd/src/core/state_engine.rs b/breadd/src/core/state_engine.rs index 5807168..060c0df 100644 --- a/breadd/src/core/state_engine.rs +++ b/breadd/src/core/state_engine.rs @@ -260,7 +260,7 @@ pub async fn run_state_engine( } if let (Some(before), Some(after)) = (before_snapshot, after_snapshot) { - for (_id, path) in watches.iter() { + for path in watches.values() { let old_val = value_at_path(&before, path).unwrap_or(Value::Null); let new_val = value_at_path(&after, path).unwrap_or(Value::Null); if old_val != new_val { diff --git a/breadd/tests/module_host_sandbox.rs b/breadd/tests/module_host_sandbox.rs index 51e57cc..d0fa9fe 100644 --- a/breadd/tests/module_host_sandbox.rs +++ b/breadd/tests/module_host_sandbox.rs @@ -137,10 +137,8 @@ enabled = false async fn wait_until_ready(&self) -> Result<()> { let deadline = Instant::now() + Duration::from_secs(8); while Instant::now() < deadline { - if self.socket_path.exists() { - if self.send_request("ping", json!({})).await.is_ok() { - return Ok(()); - } + if self.socket_path.exists() && self.send_request("ping", json!({})).await.is_ok() { + return Ok(()); } sleep(Duration::from_millis(100)).await; }