diff --git a/yazi-dds/src/body/delete.rs b/yazi-dds/src/body/delete.rs index 47ae9e79..41ae524d 100644 --- a/yazi-dds/src/body/delete.rs +++ b/yazi-dds/src/body/delete.rs @@ -28,9 +28,15 @@ impl<'a> From> for Body<'a> { impl IntoLua<'_> for BodyDelete<'static> { fn into_lua(self, lua: &Lua) -> mlua::Result> { let urls = lua.create_table_with_capacity(self.urls.len(), 0)?; + + // In most cases, `self.urls` will be `Cow::Owned`, so + // `.into_owned().into_iter()` can avoid any cloning, whereas + // `.iter().cloned()` will clone each element. + #[allow(clippy::unnecessary_to_owned)] for (i, url) in self.urls.into_owned().into_iter().enumerate() { urls.raw_set(i + 1, lua.create_any_userdata(url)?)?; } + lua.create_table_from([("urls", urls)])?.into_lua(lua) } } diff --git a/yazi-dds/src/body/trash.rs b/yazi-dds/src/body/trash.rs index 91e42a5b..cac54fd9 100644 --- a/yazi-dds/src/body/trash.rs +++ b/yazi-dds/src/body/trash.rs @@ -28,9 +28,15 @@ impl<'a> From> for Body<'a> { impl IntoLua<'_> for BodyTrash<'static> { fn into_lua(self, lua: &Lua) -> mlua::Result> { let urls = lua.create_table_with_capacity(self.urls.len(), 0)?; + + // In most cases, `self.urls` will be `Cow::Owned`, so + // `.into_owned().into_iter()` can avoid any cloning, whereas + // `.iter().cloned()` will clone each element. + #[allow(clippy::unnecessary_to_owned)] for (i, url) in self.urls.into_owned().into_iter().enumerate() { urls.raw_set(i + 1, lua.create_any_userdata(url)?)?; } + lua.create_table_from([("urls", urls)])?.into_lua(lua) } } diff --git a/yazi-fm/src/lives/lives.rs b/yazi-fm/src/lives/lives.rs index 6f09852a..fefb6888 100644 --- a/yazi-fm/src/lives/lives.rs +++ b/yazi-fm/src/lives/lives.rs @@ -37,7 +37,9 @@ impl Lives { ) -> mlua::Result { let result = LUA.scope(|scope| { defer! { SCOPE.drop(); }; - SCOPE.init(unsafe { mem::transmute(scope) }); + SCOPE.init(unsafe { + mem::transmute::<&mlua::Scope<'a, 'a>, &mlua::Scope<'static, 'static>>(scope) + }); LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?; let globals = LUA.globals(); diff --git a/yazi-shared/src/ro_cell.rs b/yazi-shared/src/ro_cell.rs index 4ed209f3..5d7c95c8 100644 --- a/yazi-shared/src/ro_cell.rs +++ b/yazi-shared/src/ro_cell.rs @@ -43,6 +43,10 @@ impl RoCell { fn initialized(&self) -> bool { unsafe { (*self.0.get()).is_some() } } } +impl Default for RoCell { + fn default() -> Self { Self::new() } +} + impl Deref for RoCell { type Target = T;