diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-12-19 22:11:52 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2022-12-19 22:26:44 +0000 |
commit | c60f633a62e62b33173cc5567b17dd005a89e6cc (patch) | |
tree | b472200b7567ee7ce00fd852767da1b8e24d5afd /src/types.rs | |
parent | 56abc4a700b246dcd4b6c0b0a818779577067cc2 (diff) | |
download | mlua-c60f633a62e62b33173cc5567b17dd005a89e6cc.zip |
Add "unstable" feature flag.
Hide owned types under the new feature flag.
Drop OwnedString/OwnedThread types (unlikely they are useful).
Diffstat (limited to 'src/types.rs')
-rw-r--r-- | src/types.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs index a02c21a..ace1bf6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -192,6 +192,7 @@ impl<'lua> LuaRef<'lua> { } } + #[cfg(feature = "unstable")] #[inline] pub(crate) fn into_owned(self) -> LuaOwnedRef { self.lua.make_owned_ref(self) @@ -232,23 +233,28 @@ impl<'lua> PartialEq for LuaRef<'lua> { } } +#[cfg(feature = "unstable")] pub(crate) struct LuaOwnedRef { pub(crate) lua: Lua, pub(crate) index: c_int, + _non_send: std::marker::PhantomData<*const ()>, } +#[cfg(feature = "unstable")] impl fmt::Debug for LuaOwnedRef { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "OwnedRef({})", self.index) } } +#[cfg(feature = "unstable")] impl Clone for LuaOwnedRef { fn clone(&self) -> Self { self.lua.make_owned_ref(self.to_ref().clone()) } } +#[cfg(feature = "unstable")] impl Drop for LuaOwnedRef { fn drop(&mut self) { drop(LuaRef { @@ -259,7 +265,24 @@ impl Drop for LuaOwnedRef { } } +#[cfg(feature = "unstable")] impl LuaOwnedRef { + pub(crate) const fn new(lua: Lua, index: c_int) -> Self { + #[cfg(feature = "send")] + { + let _lua = lua; + let _index = index; + panic!("mlua must be compiled without \"send\" feature to use Owned types"); + } + + #[cfg(not(feature = "send"))] + LuaOwnedRef { + lua, + index, + _non_send: std::marker::PhantomData, + } + } + pub(crate) const fn to_ref(&self) -> LuaRef { LuaRef { lua: &self.lua, @@ -275,4 +298,7 @@ mod assertions { static_assertions::assert_impl_all!(RegistryKey: Send, Sync); static_assertions::assert_not_impl_any!(LuaRef: Send); + + #[cfg(feature = "unstable")] + static_assertions::assert_not_impl_any!(LuaOwnedRef: Send); } |