refactor: fix Clippy warnings

This commit is contained in:
Lauri Niskanen 2024-07-19 11:35:34 +03:00
parent d6081fbe6f
commit 8fec498335
No known key found for this signature in database
GPG key ID: 807DCEAC3AEB1848
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)?;
#[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)
}
}

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)?;
#[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)
}
}

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

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