Add "unstable" feature flag.
Hide owned types under the new feature flag. Drop OwnedString/OwnedThread types (unlikely they are useful).
This commit is contained in:
parent
56abc4a700
commit
c60f633a62
|
@ -39,6 +39,7 @@ async = ["futures-core", "futures-task", "futures-util"]
|
||||||
send = []
|
send = []
|
||||||
serialize = ["serde", "erased-serde"]
|
serialize = ["serde", "erased-serde"]
|
||||||
macros = ["mlua_derive/macros"]
|
macros = ["mlua_derive/macros"]
|
||||||
|
unstable = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mlua_derive = { version = "=0.8.0", optional = true, path = "mlua_derive" }
|
mlua_derive = { version = "=0.8.0", optional = true, path = "mlua_derive" }
|
||||||
|
@ -90,7 +91,7 @@ required-features = ["async", "serialize", "macros"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "async_http_server"
|
name = "async_http_server"
|
||||||
required-features = ["async", "macros"]
|
required-features = ["async", "macros", "unstable"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "async_tcp_server"
|
name = "async_tcp_server"
|
||||||
|
|
|
@ -11,15 +11,18 @@ use bstr::{BStr, BString};
|
||||||
use num_traits::cast;
|
use num_traits::cast;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::function::{Function, OwnedFunction};
|
use crate::function::Function;
|
||||||
use crate::lua::Lua;
|
use crate::lua::Lua;
|
||||||
use crate::string::{OwnedString, String};
|
use crate::string::String;
|
||||||
use crate::table::{OwnedTable, Table};
|
use crate::table::Table;
|
||||||
use crate::thread::{OwnedThread, Thread};
|
use crate::thread::Thread;
|
||||||
use crate::types::{LightUserData, MaybeSend};
|
use crate::types::{LightUserData, MaybeSend};
|
||||||
use crate::userdata::{AnyUserData, OwnedAnyUserData, UserData};
|
use crate::userdata::{AnyUserData, UserData};
|
||||||
use crate::value::{FromLua, Nil, ToLua, Value};
|
use crate::value::{FromLua, Nil, ToLua, Value};
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
use crate::{function::OwnedFunction, table::OwnedTable, userdata::OwnedAnyUserData};
|
||||||
|
|
||||||
impl<'lua> ToLua<'lua> for Value<'lua> {
|
impl<'lua> ToLua<'lua> for Value<'lua> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -54,20 +57,6 @@ impl<'lua> FromLua<'lua> for String<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> ToLua<'lua> for OwnedString {
|
|
||||||
#[inline]
|
|
||||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
|
||||||
Ok(Value::String(String(lua.adopt_owned_ref(self.0))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> FromLua<'lua> for OwnedString {
|
|
||||||
#[inline]
|
|
||||||
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedString> {
|
|
||||||
String::from_lua(value, lua).map(|s| s.into_owned())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> ToLua<'lua> for Table<'lua> {
|
impl<'lua> ToLua<'lua> for Table<'lua> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -89,6 +78,7 @@ impl<'lua> FromLua<'lua> for Table<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> ToLua<'lua> for OwnedTable {
|
impl<'lua> ToLua<'lua> for OwnedTable {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -96,6 +86,7 @@ impl<'lua> ToLua<'lua> for OwnedTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> FromLua<'lua> for OwnedTable {
|
impl<'lua> FromLua<'lua> for OwnedTable {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedTable> {
|
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedTable> {
|
||||||
|
@ -124,6 +115,7 @@ impl<'lua> FromLua<'lua> for Function<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> ToLua<'lua> for OwnedFunction {
|
impl<'lua> ToLua<'lua> for OwnedFunction {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -131,6 +123,7 @@ impl<'lua> ToLua<'lua> for OwnedFunction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> FromLua<'lua> for OwnedFunction {
|
impl<'lua> FromLua<'lua> for OwnedFunction {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedFunction> {
|
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedFunction> {
|
||||||
|
@ -159,20 +152,6 @@ impl<'lua> FromLua<'lua> for Thread<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> ToLua<'lua> for OwnedThread {
|
|
||||||
#[inline]
|
|
||||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
|
||||||
Ok(Value::Thread(Thread(lua.adopt_owned_ref(self.0))))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> FromLua<'lua> for OwnedThread {
|
|
||||||
#[inline]
|
|
||||||
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedThread> {
|
|
||||||
Thread::from_lua(value, lua).map(|s| s.into_owned())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> ToLua<'lua> for AnyUserData<'lua> {
|
impl<'lua> ToLua<'lua> for AnyUserData<'lua> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -194,6 +173,7 @@ impl<'lua> FromLua<'lua> for AnyUserData<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> ToLua<'lua> for OwnedAnyUserData {
|
impl<'lua> ToLua<'lua> for OwnedAnyUserData {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -201,6 +181,7 @@ impl<'lua> ToLua<'lua> for OwnedAnyUserData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl<'lua> FromLua<'lua> for OwnedAnyUserData {
|
impl<'lua> FromLua<'lua> for OwnedAnyUserData {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedAnyUserData> {
|
fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<OwnedAnyUserData> {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::slice;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
use crate::types::{LuaOwnedRef, LuaRef};
|
use crate::types::LuaRef;
|
||||||
use crate::util::{
|
use crate::util::{
|
||||||
assert_stack, check_stack, error_traceback, pop_error, ptr_to_cstr_bytes, StackGuard,
|
assert_stack, check_stack, error_traceback, pop_error, ptr_to_cstr_bytes, StackGuard,
|
||||||
};
|
};
|
||||||
|
@ -19,9 +19,12 @@ use {futures_core::future::LocalBoxFuture, futures_util::future};
|
||||||
pub struct Function<'lua>(pub(crate) LuaRef<'lua>);
|
pub struct Function<'lua>(pub(crate) LuaRef<'lua>);
|
||||||
|
|
||||||
/// Owned handle to an internal Lua function.
|
/// Owned handle to an internal Lua function.
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct OwnedFunction(pub(crate) LuaOwnedRef);
|
pub struct OwnedFunction(pub(crate) crate::types::LuaOwnedRef);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl OwnedFunction {
|
impl OwnedFunction {
|
||||||
/// Get borrowed handle to the underlying Lua function.
|
/// Get borrowed handle to the underlying Lua function.
|
||||||
pub const fn to_ref(&self) -> Function {
|
pub const fn to_ref(&self) -> Function {
|
||||||
|
@ -391,6 +394,8 @@ impl<'lua> Function<'lua> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this handle to owned version.
|
/// Convert this handle to owned version.
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_owned(self) -> OwnedFunction {
|
pub fn into_owned(self) -> OwnedFunction {
|
||||||
OwnedFunction(self.0.into_owned())
|
OwnedFunction(self.0.into_owned())
|
||||||
|
@ -408,4 +413,7 @@ mod assertions {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
static_assertions::assert_not_impl_any!(Function: Send);
|
static_assertions::assert_not_impl_any!(Function: Send);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
static_assertions::assert_not_impl_any!(OwnedFunction: Send);
|
||||||
}
|
}
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -108,15 +108,15 @@ pub use crate::{ffi::lua_CFunction, ffi::lua_State};
|
||||||
|
|
||||||
pub use crate::chunk::{AsChunk, Chunk, ChunkMode};
|
pub use crate::chunk::{AsChunk, Chunk, ChunkMode};
|
||||||
pub use crate::error::{Error, ExternalError, ExternalResult, Result};
|
pub use crate::error::{Error, ExternalError, ExternalResult, Result};
|
||||||
pub use crate::function::{Function, FunctionInfo, OwnedFunction};
|
pub use crate::function::{Function, FunctionInfo};
|
||||||
pub use crate::hook::{Debug, DebugEvent, DebugNames, DebugSource, DebugStack};
|
pub use crate::hook::{Debug, DebugEvent, DebugNames, DebugSource, DebugStack};
|
||||||
pub use crate::lua::{GCMode, Lua, LuaOptions};
|
pub use crate::lua::{GCMode, Lua, LuaOptions};
|
||||||
pub use crate::multi::Variadic;
|
pub use crate::multi::Variadic;
|
||||||
pub use crate::scope::Scope;
|
pub use crate::scope::Scope;
|
||||||
pub use crate::stdlib::StdLib;
|
pub use crate::stdlib::StdLib;
|
||||||
pub use crate::string::{OwnedString, String};
|
pub use crate::string::String;
|
||||||
pub use crate::table::{OwnedTable, Table, TableExt, TablePairs, TableSequence};
|
pub use crate::table::{Table, TableExt, TablePairs, TableSequence};
|
||||||
pub use crate::thread::{OwnedThread, Thread, ThreadStatus};
|
pub use crate::thread::{Thread, ThreadStatus};
|
||||||
pub use crate::types::{Integer, LightUserData, Number, RegistryKey};
|
pub use crate::types::{Integer, LightUserData, Number, RegistryKey};
|
||||||
pub use crate::userdata::{
|
pub use crate::userdata::{
|
||||||
AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMetatable, UserDataMethods,
|
AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMetatable, UserDataMethods,
|
||||||
|
@ -148,6 +148,10 @@ pub mod serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate mlua_derive;
|
extern crate mlua_derive;
|
||||||
|
|
||||||
|
// Unstable features
|
||||||
|
#[cfg(all(feature = "unstable", not(feature = "send")))]
|
||||||
|
pub use crate::{function::OwnedFunction, table::OwnedTable};
|
||||||
|
|
||||||
/// Create a type that implements [`AsChunk`] and can capture Rust variables.
|
/// Create a type that implements [`AsChunk`] and can capture Rust variables.
|
||||||
///
|
///
|
||||||
/// This macro allows to write Lua code directly in Rust code.
|
/// This macro allows to write Lua code directly in Rust code.
|
||||||
|
|
17
src/lua.rs
17
src/lua.rs
|
@ -26,8 +26,8 @@ use crate::string::String;
|
||||||
use crate::table::Table;
|
use crate::table::Table;
|
||||||
use crate::thread::Thread;
|
use crate::thread::Thread;
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
Callback, CallbackUpvalue, DestructedUserdata, Integer, LightUserData, LuaOwnedRef, LuaRef,
|
Callback, CallbackUpvalue, DestructedUserdata, Integer, LightUserData, LuaRef, MaybeSend,
|
||||||
MaybeSend, Number, RegistryKey,
|
Number, RegistryKey,
|
||||||
};
|
};
|
||||||
use crate::userdata::{AnyUserData, UserData, UserDataCell};
|
use crate::userdata::{AnyUserData, UserData, UserDataCell};
|
||||||
use crate::userdata_impl::{StaticUserDataFields, StaticUserDataMethods, UserDataProxy};
|
use crate::userdata_impl::{StaticUserDataFields, StaticUserDataMethods, UserDataProxy};
|
||||||
|
@ -2469,17 +2469,16 @@ impl Lua {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_owned_ref(&self, lref: LuaRef) -> LuaOwnedRef {
|
#[cfg(feature = "unstable")]
|
||||||
assert!(lref.drop, "Cannot make owned non-drop reference");
|
pub(crate) fn make_owned_ref(&self, lref: LuaRef) -> crate::types::LuaOwnedRef {
|
||||||
let owned_ref = LuaOwnedRef {
|
assert!(lref.drop, "Cannot turn non-drop reference into owned");
|
||||||
lua: Lua(self.0.clone()),
|
let owned_ref = crate::types::LuaOwnedRef::new(Lua(self.0.clone()), lref.index);
|
||||||
index: lref.index,
|
|
||||||
};
|
|
||||||
mem::forget(lref);
|
mem::forget(lref);
|
||||||
owned_ref
|
owned_ref
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn adopt_owned_ref(&self, loref: LuaOwnedRef) -> LuaRef {
|
#[cfg(feature = "unstable")]
|
||||||
|
pub(crate) fn adopt_owned_ref(&self, loref: crate::types::LuaOwnedRef) -> LuaRef {
|
||||||
assert!(
|
assert!(
|
||||||
Arc::ptr_eq(&loref.lua.0, &self.0),
|
Arc::ptr_eq(&loref.lua.0, &self.0),
|
||||||
"Lua instance passed Value created from a different main Lua state"
|
"Lua instance passed Value created from a different main Lua state"
|
||||||
|
|
|
@ -12,7 +12,7 @@ use {
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
use crate::types::{LuaOwnedRef, LuaRef};
|
use crate::types::LuaRef;
|
||||||
|
|
||||||
/// Handle to an internal Lua string.
|
/// Handle to an internal Lua string.
|
||||||
///
|
///
|
||||||
|
@ -20,17 +20,6 @@ use crate::types::{LuaOwnedRef, LuaRef};
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct String<'lua>(pub(crate) LuaRef<'lua>);
|
pub struct String<'lua>(pub(crate) LuaRef<'lua>);
|
||||||
|
|
||||||
/// Owned handle to an internal Lua string.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct OwnedString(pub(crate) LuaOwnedRef);
|
|
||||||
|
|
||||||
impl OwnedString {
|
|
||||||
/// Get borrowed handle to the underlying Lua string.
|
|
||||||
pub const fn to_ref(&self) -> String {
|
|
||||||
String(self.0.to_ref())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'lua> String<'lua> {
|
impl<'lua> String<'lua> {
|
||||||
/// Get a `&str` slice if the Lua string is valid UTF-8.
|
/// Get a `&str` slice if the Lua string is valid UTF-8.
|
||||||
///
|
///
|
||||||
|
@ -133,12 +122,6 @@ impl<'lua> String<'lua> {
|
||||||
let ref_thread = self.0.lua.ref_thread();
|
let ref_thread = self.0.lua.ref_thread();
|
||||||
unsafe { ffi::lua_topointer(ref_thread, self.0.index) }
|
unsafe { ffi::lua_topointer(ref_thread, self.0.index) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this handle to owned version.
|
|
||||||
#[inline]
|
|
||||||
pub fn into_owned(self) -> OwnedString {
|
|
||||||
OwnedString(self.0.into_owned())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> AsRef<[u8]> for String<'lua> {
|
impl<'lua> AsRef<[u8]> for String<'lua> {
|
||||||
|
|
12
src/table.rs
12
src/table.rs
|
@ -11,7 +11,7 @@ use {
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
use crate::function::Function;
|
use crate::function::Function;
|
||||||
use crate::types::{Integer, LuaOwnedRef, LuaRef};
|
use crate::types::{Integer, LuaRef};
|
||||||
use crate::util::{assert_stack, check_stack, StackGuard};
|
use crate::util::{assert_stack, check_stack, StackGuard};
|
||||||
use crate::value::{FromLua, FromLuaMulti, Nil, ToLua, ToLuaMulti, Value};
|
use crate::value::{FromLua, FromLuaMulti, Nil, ToLua, ToLuaMulti, Value};
|
||||||
|
|
||||||
|
@ -23,9 +23,12 @@ use {futures_core::future::LocalBoxFuture, futures_util::future};
|
||||||
pub struct Table<'lua>(pub(crate) LuaRef<'lua>);
|
pub struct Table<'lua>(pub(crate) LuaRef<'lua>);
|
||||||
|
|
||||||
/// Owned handle to an internal Lua table.
|
/// Owned handle to an internal Lua table.
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct OwnedTable(pub(crate) LuaOwnedRef);
|
pub struct OwnedTable(pub(crate) crate::types::LuaOwnedRef);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl OwnedTable {
|
impl OwnedTable {
|
||||||
/// Get borrowed handle to the underlying Lua table.
|
/// Get borrowed handle to the underlying Lua table.
|
||||||
pub const fn to_ref(&self) -> Table {
|
pub const fn to_ref(&self) -> Table {
|
||||||
|
@ -538,6 +541,8 @@ impl<'lua> Table<'lua> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this handle to owned version.
|
/// Convert this handle to owned version.
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_owned(self) -> OwnedTable {
|
pub fn into_owned(self) -> OwnedTable {
|
||||||
OwnedTable(self.0.into_owned())
|
OwnedTable(self.0.into_owned())
|
||||||
|
@ -1024,4 +1029,7 @@ mod assertions {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
static_assertions::assert_not_impl_any!(Table: Send);
|
static_assertions::assert_not_impl_any!(Table: Send);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
static_assertions::assert_not_impl_any!(OwnedTable: Send);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::os::raw::c_int;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
use crate::types::{LuaOwnedRef, LuaRef};
|
use crate::types::LuaRef;
|
||||||
use crate::util::{check_stack, error_traceback_thread, pop_error, StackGuard};
|
use crate::util::{check_stack, error_traceback_thread, pop_error, StackGuard};
|
||||||
use crate::value::{FromLuaMulti, ToLuaMulti};
|
use crate::value::{FromLuaMulti, ToLuaMulti};
|
||||||
|
|
||||||
|
@ -47,17 +47,6 @@ pub enum ThreadStatus {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Thread<'lua>(pub(crate) LuaRef<'lua>);
|
pub struct Thread<'lua>(pub(crate) LuaRef<'lua>);
|
||||||
|
|
||||||
/// Owned handle to an internal Lua thread.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct OwnedThread(pub(crate) LuaOwnedRef);
|
|
||||||
|
|
||||||
impl OwnedThread {
|
|
||||||
/// Get borrowed handle to the underlying Lua thread.
|
|
||||||
pub const fn to_ref(&self) -> Thread {
|
|
||||||
Thread(self.0.to_ref())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Thread (coroutine) representation as an async [`Future`] or [`Stream`].
|
/// Thread (coroutine) representation as an async [`Future`] or [`Stream`].
|
||||||
///
|
///
|
||||||
/// Requires `feature = "async"`
|
/// Requires `feature = "async"`
|
||||||
|
@ -346,12 +335,6 @@ impl<'lua> Thread<'lua> {
|
||||||
protect_lua!(state, 0, 0, |_| ffi::luaL_sandboxthread(thread))
|
protect_lua!(state, 0, 0, |_| ffi::luaL_sandboxthread(thread))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this handle to owned version.
|
|
||||||
#[inline]
|
|
||||||
pub fn into_owned(self) -> OwnedThread {
|
|
||||||
OwnedThread(self.0.into_owned())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> PartialEq for Thread<'lua> {
|
impl<'lua> PartialEq for Thread<'lua> {
|
||||||
|
|
26
src/types.rs
26
src/types.rs
|
@ -192,6 +192,7 @@ impl<'lua> LuaRef<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn into_owned(self) -> LuaOwnedRef {
|
pub(crate) fn into_owned(self) -> LuaOwnedRef {
|
||||||
self.lua.make_owned_ref(self)
|
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) struct LuaOwnedRef {
|
||||||
pub(crate) lua: Lua,
|
pub(crate) lua: Lua,
|
||||||
pub(crate) index: c_int,
|
pub(crate) index: c_int,
|
||||||
|
_non_send: std::marker::PhantomData<*const ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl fmt::Debug for LuaOwnedRef {
|
impl fmt::Debug for LuaOwnedRef {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "OwnedRef({})", self.index)
|
write!(f, "OwnedRef({})", self.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl Clone for LuaOwnedRef {
|
impl Clone for LuaOwnedRef {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
self.lua.make_owned_ref(self.to_ref().clone())
|
self.lua.make_owned_ref(self.to_ref().clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl Drop for LuaOwnedRef {
|
impl Drop for LuaOwnedRef {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
drop(LuaRef {
|
drop(LuaRef {
|
||||||
|
@ -259,7 +265,24 @@ impl Drop for LuaOwnedRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl LuaOwnedRef {
|
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 {
|
pub(crate) const fn to_ref(&self) -> LuaRef {
|
||||||
LuaRef {
|
LuaRef {
|
||||||
lua: &self.lua,
|
lua: &self.lua,
|
||||||
|
@ -275,4 +298,7 @@ mod assertions {
|
||||||
|
|
||||||
static_assertions::assert_impl_all!(RegistryKey: Send, Sync);
|
static_assertions::assert_impl_all!(RegistryKey: Send, Sync);
|
||||||
static_assertions::assert_not_impl_any!(LuaRef: Send);
|
static_assertions::assert_not_impl_any!(LuaRef: Send);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
static_assertions::assert_not_impl_any!(LuaOwnedRef: Send);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::ffi;
|
||||||
use crate::function::Function;
|
use crate::function::Function;
|
||||||
use crate::lua::Lua;
|
use crate::lua::Lua;
|
||||||
use crate::table::{Table, TablePairs};
|
use crate::table::{Table, TablePairs};
|
||||||
use crate::types::{Callback, LuaOwnedRef, LuaRef, MaybeSend};
|
use crate::types::{Callback, LuaRef, MaybeSend};
|
||||||
use crate::util::{check_stack, get_userdata, take_userdata, StackGuard};
|
use crate::util::{check_stack, get_userdata, take_userdata, StackGuard};
|
||||||
use crate::value::{FromLua, FromLuaMulti, ToLua, ToLuaMulti};
|
use crate::value::{FromLua, FromLuaMulti, ToLua, ToLuaMulti};
|
||||||
|
|
||||||
|
@ -782,9 +782,12 @@ impl Serialize for UserDataSerializeError {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AnyUserData<'lua>(pub(crate) LuaRef<'lua>);
|
pub struct AnyUserData<'lua>(pub(crate) LuaRef<'lua>);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct OwnedAnyUserData(pub(crate) LuaOwnedRef);
|
pub struct OwnedAnyUserData(pub(crate) crate::types::LuaOwnedRef);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
impl OwnedAnyUserData {
|
impl OwnedAnyUserData {
|
||||||
pub const fn to_ref(&self) -> AnyUserData {
|
pub const fn to_ref(&self) -> AnyUserData {
|
||||||
AnyUserData(self.0.to_ref())
|
AnyUserData(self.0.to_ref())
|
||||||
|
@ -1067,6 +1070,8 @@ impl<'lua> AnyUserData<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_owned(self) -> OwnedAnyUserData {
|
pub fn into_owned(self) -> OwnedAnyUserData {
|
||||||
OwnedAnyUserData(self.0.into_owned())
|
OwnedAnyUserData(self.0.into_owned())
|
||||||
|
@ -1238,4 +1243,7 @@ mod assertions {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
static_assertions::assert_not_impl_any!(AnyUserData: Send);
|
static_assertions::assert_not_impl_any!(AnyUserData: Send);
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable")]
|
||||||
|
static_assertions::assert_not_impl_any!(OwnedAnyUserData: Send);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue