refactor: fix Clippy warnings (#1312)

Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
Lauri Niskanen 2024-07-20 11:34:04 +03:00 committed by GitHub
parent bba32ed0b2
commit 093c13ac22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 1 deletions

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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();

View file

@ -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;