mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: fix Clippy warnings (#1312)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
bba32ed0b2
commit
093c13ac22
4 changed files with 19 additions and 1 deletions
|
|
@ -28,9 +28,15 @@ impl<'a> From<BodyDelete<'a>> for Body<'a> {
|
|||
impl IntoLua<'_> for BodyDelete<'static> {
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value<'_>> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,15 @@ impl<'a> From<BodyTrash<'a>> for Body<'a> {
|
|||
impl IntoLua<'_> for BodyTrash<'static> {
|
||||
fn into_lua(self, lua: &Lua) -> mlua::Result<Value<'_>> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ impl Lives {
|
|||
) -> mlua::Result<T> {
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ impl<T> RoCell<T> {
|
|||
fn initialized(&self) -> bool { unsafe { (*self.0.get()).is_some() } }
|
||||
}
|
||||
|
||||
impl<T> Default for RoCell<T> {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl<T> Deref for RoCell<T> {
|
||||
type Target = T;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue