diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2023-02-15 09:20:03 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2023-02-15 09:20:03 +0000 |
commit | b8e3290f356249d701ebdd2566deb55de2359da0 (patch) | |
tree | b357ab1994bb39f683d4cc0bf89461ba79b86f8f /src/types.rs | |
parent | 03ab8283429ee5ed57241bc5353e1f9c95b7be21 (diff) | |
download | mlua-b8e3290f356249d701ebdd2566deb55de2359da0.zip |
Update LuaRef/LuaOwnedRef
Move content of `Lua::make_owned_ref` into `LuaRef::into_owned`
Add crate-visible `Lua::clone` function (not trait)
Diffstat (limited to 'src/types.rs')
-rw-r--r-- | src/types.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/types.rs b/src/types.rs index ace1bf6..47bd9db 100644 --- a/src/types.rs +++ b/src/types.rs @@ -195,7 +195,10 @@ impl<'lua> LuaRef<'lua> { #[cfg(feature = "unstable")] #[inline] pub(crate) fn into_owned(self) -> LuaOwnedRef { - self.lua.make_owned_ref(self) + assert!(self.drop, "Cannot turn non-drop reference into owned"); + let owned_ref = LuaOwnedRef::new(self.lua.clone(), self.index); + mem::forget(self); + owned_ref } } @@ -214,7 +217,7 @@ impl<'lua> Clone for LuaRef<'lua> { impl<'lua> Drop for LuaRef<'lua> { fn drop(&mut self) { if self.drop { - self.lua.drop_ref(self); + self.lua.drop_ref_index(self.index); } } } @@ -250,18 +253,14 @@ impl fmt::Debug for LuaOwnedRef { #[cfg(feature = "unstable")] impl Clone for LuaOwnedRef { fn clone(&self) -> Self { - self.lua.make_owned_ref(self.to_ref().clone()) + self.to_ref().clone().into_owned() } } #[cfg(feature = "unstable")] impl Drop for LuaOwnedRef { fn drop(&mut self) { - drop(LuaRef { - lua: &self.lua, - index: self.index, - drop: true, - }); + self.lua.drop_ref_index(self.index); } } |