Remove unstable feature flag from Function::wrap/wrap_mut/wrap_async
This commit is contained in:
parent
f9d1213c4b
commit
65e72f39ae
|
@ -9,7 +9,7 @@ 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;
|
use crate::function::{Function, WrappedFunction};
|
||||||
use crate::lua::Lua;
|
use crate::lua::Lua;
|
||||||
use crate::string::String;
|
use crate::string::String;
|
||||||
use crate::table::Table;
|
use crate::table::Table;
|
||||||
|
@ -19,13 +19,9 @@ use crate::userdata::{AnyUserData, UserData, UserDataRef, UserDataRefMut};
|
||||||
use crate::value::{FromLua, IntoLua, Nil, Value};
|
use crate::value::{FromLua, IntoLua, Nil, Value};
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
use crate::{
|
use crate::{function::OwnedFunction, table::OwnedTable, userdata::OwnedAnyUserData};
|
||||||
function::{OwnedFunction, WrappedFunction},
|
|
||||||
table::OwnedTable,
|
|
||||||
userdata::OwnedAnyUserData,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
#[cfg(feature = "async")]
|
||||||
use crate::function::WrappedAsyncFunction;
|
use crate::function::WrappedAsyncFunction;
|
||||||
|
|
||||||
impl<'lua> IntoLua<'lua> for Value<'lua> {
|
impl<'lua> IntoLua<'lua> for Value<'lua> {
|
||||||
|
@ -136,7 +132,6 @@ impl<'lua> FromLua<'lua> for OwnedFunction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
impl<'lua> IntoLua<'lua> for WrappedFunction<'lua> {
|
impl<'lua> IntoLua<'lua> for WrappedFunction<'lua> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
@ -144,7 +139,7 @@ impl<'lua> IntoLua<'lua> for WrappedFunction<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
#[cfg(feature = "async")]
|
||||||
impl<'lua> IntoLua<'lua> for WrappedAsyncFunction<'lua> {
|
impl<'lua> IntoLua<'lua> for WrappedAsyncFunction<'lua> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
fn into_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os::raw::{c_int, c_void};
|
use std::os::raw::{c_int, c_void};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -5,26 +6,20 @@ use std::slice;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
|
use crate::lua::Lua;
|
||||||
use crate::memory::MemoryState;
|
use crate::memory::MemoryState;
|
||||||
use crate::types::LuaRef;
|
use crate::types::{Callback, LuaRef, MaybeSend};
|
||||||
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,
|
||||||
};
|
};
|
||||||
use crate::value::{FromLuaMulti, IntoLuaMulti};
|
use crate::value::{FromLuaMulti, IntoLua, IntoLuaMulti};
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
use {
|
|
||||||
crate::lua::Lua,
|
|
||||||
crate::types::{Callback, MaybeSend},
|
|
||||||
crate::value::IntoLua,
|
|
||||||
std::cell::RefCell,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
use {futures_core::future::LocalBoxFuture, futures_util::future};
|
use {
|
||||||
|
crate::types::AsyncCallback,
|
||||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
futures_core::future::{Future, LocalBoxFuture},
|
||||||
use {crate::types::AsyncCallback, futures_core::Future, futures_util::TryFutureExt};
|
futures_util::{future, TryFutureExt},
|
||||||
|
};
|
||||||
|
|
||||||
/// Handle to an internal Lua function.
|
/// Handle to an internal Lua function.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -420,22 +415,19 @@ impl<'lua> PartialEq for Function<'lua> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub(crate) struct WrappedFunction<'lua>(pub(crate) Callback<'lua, 'static>);
|
pub(crate) struct WrappedFunction<'lua>(pub(crate) Callback<'lua, 'static>);
|
||||||
|
|
||||||
#[cfg(all(feature = "async", feature = "unstable"))]
|
#[cfg(feature = "async")]
|
||||||
pub(crate) struct WrappedAsyncFunction<'lua>(pub(crate) AsyncCallback<'lua, 'static>);
|
pub(crate) struct WrappedAsyncFunction<'lua>(pub(crate) AsyncCallback<'lua, 'static>);
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
|
|
||||||
impl<'lua> Function<'lua> {
|
impl<'lua> Function<'lua> {
|
||||||
/// Wraps a Rust function or closure, returning an opaque type that implements [`IntoLua`] trait.
|
/// Wraps a Rust function or closure, returning an opaque type that implements [`IntoLua`] trait.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrap<F, A, R>(func: F) -> impl IntoLua<'lua>
|
pub fn wrap<A, R, F>(func: F) -> impl IntoLua<'lua>
|
||||||
where
|
where
|
||||||
F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
|
|
||||||
A: FromLuaMulti<'lua>,
|
A: FromLuaMulti<'lua>,
|
||||||
R: IntoLuaMulti<'lua>,
|
R: IntoLuaMulti<'lua>,
|
||||||
|
F: Fn(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
|
||||||
{
|
{
|
||||||
WrappedFunction(Box::new(move |lua, args| {
|
WrappedFunction(Box::new(move |lua, args| {
|
||||||
func(lua, A::from_lua_multi(args, lua)?)?.into_lua_multi(lua)
|
func(lua, A::from_lua_multi(args, lua)?)?.into_lua_multi(lua)
|
||||||
|
@ -444,11 +436,11 @@ impl<'lua> Function<'lua> {
|
||||||
|
|
||||||
/// Wraps a Rust mutable closure, returning an opaque type that implements [`IntoLua`] trait.
|
/// Wraps a Rust mutable closure, returning an opaque type that implements [`IntoLua`] trait.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrap_mut<F, A, R>(func: F) -> impl IntoLua<'lua>
|
pub fn wrap_mut<A, R, F>(func: F) -> impl IntoLua<'lua>
|
||||||
where
|
where
|
||||||
F: FnMut(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
|
|
||||||
A: FromLuaMulti<'lua>,
|
A: FromLuaMulti<'lua>,
|
||||||
R: IntoLuaMulti<'lua>,
|
R: IntoLuaMulti<'lua>,
|
||||||
|
F: FnMut(&'lua Lua, A) -> Result<R> + MaybeSend + 'static,
|
||||||
{
|
{
|
||||||
let func = RefCell::new(func);
|
let func = RefCell::new(func);
|
||||||
WrappedFunction(Box::new(move |lua, args| {
|
WrappedFunction(Box::new(move |lua, args| {
|
||||||
|
@ -459,14 +451,15 @@ impl<'lua> Function<'lua> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wraps a Rust async function or closure, returning an opaque type that implements [`IntoLua`] trait.
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
|
||||||
pub fn wrap_async<F, A, FR, R>(func: F) -> impl IntoLua<'lua>
|
pub fn wrap_async<A, R, F, FR>(func: F) -> impl IntoLua<'lua>
|
||||||
where
|
where
|
||||||
F: Fn(&'lua Lua, A) -> FR + MaybeSend + 'static,
|
|
||||||
A: FromLuaMulti<'lua>,
|
A: FromLuaMulti<'lua>,
|
||||||
FR: Future<Output = Result<R>> + 'lua,
|
|
||||||
R: IntoLuaMulti<'lua>,
|
R: IntoLuaMulti<'lua>,
|
||||||
|
F: Fn(&'lua Lua, A) -> FR + MaybeSend + 'static,
|
||||||
|
FR: Future<Output = Result<R>> + 'lua,
|
||||||
{
|
{
|
||||||
WrappedAsyncFunction(Box::new(move |lua, args| {
|
WrappedAsyncFunction(Box::new(move |lua, args| {
|
||||||
let args = match A::from_lua_multi(args, lua) {
|
let args = match A::from_lua_multi(args, lua) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ async fn test_async_function() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_async_function_wrap() -> Result<()> {
|
async fn test_async_function_wrap() -> Result<()> {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
|
|
|
@ -168,7 +168,6 @@ fn test_function_info() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_function_wrap() -> Result<()> {
|
fn test_function_wrap() -> Result<()> {
|
||||||
use mlua::Error;
|
use mlua::Error;
|
||||||
|
|
Loading…
Reference in New Issue