mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: fix Clippy warnings
This commit is contained in:
parent
d6081fbe6f
commit
8fec498335
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)?;
|
||||
|
||||
#[allow(clippy::unnecessary_to_owned)]
|
||||
// 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.
|
||||
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)?;
|
||||
|
||||
#[allow(clippy::unnecessary_to_owned)]
|
||||
// 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.
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ pub struct RoCell<T>(UnsafeCell<Option<T>>);
|
|||
|
||||
unsafe impl<T> Sync for RoCell<T> {}
|
||||
|
||||
impl<T> Default for RoCell<T> {
|
||||
fn default() -> Self { Self::new() }
|
||||
}
|
||||
|
||||
impl<T> RoCell<T> {
|
||||
#[inline]
|
||||
pub const fn new() -> Self { Self(UnsafeCell::new(None)) }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue