diff --git a/src/function.rs b/src/function.rs index 7692575..7151c34 100644 --- a/src/function.rs +++ b/src/function.rs @@ -10,7 +10,7 @@ use crate::util::{ use crate::value::{FromLuaMulti, MultiValue, ToLuaMulti}; #[cfg(feature = "async")] -use futures_core::future::LocalBoxFuture; +use {futures_core::future::LocalBoxFuture, futures_util::future}; /// Handle to an internal Lua function. #[derive(Clone, Debug)] @@ -123,7 +123,7 @@ impl<'lua> Function<'lua> { let lua = self.0.lua; match lua.create_thread(self.clone()) { Ok(t) => Box::pin(t.into_async(args)), - Err(e) => Box::pin(futures_util::future::err(e)), + Err(e) => Box::pin(future::err(e)), } } diff --git a/src/lua.rs b/src/lua.rs index 9ba6afe..90b54de 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -27,13 +27,12 @@ use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Va #[cfg(feature = "async")] use { crate::types::AsyncCallback, - futures_core::future::LocalBoxFuture, - futures_task::noop_waker, - futures_util::future::{self, FutureExt, TryFutureExt}, - std::{ - future::Future, + futures_core::{ + future::{Future, LocalBoxFuture}, task::{Context, Poll, Waker}, }, + futures_task::noop_waker, + futures_util::future::{self, TryFutureExt}, }; /// Top level Lua struct which holds the Lua state itself. @@ -530,12 +529,10 @@ impl Lua { { self.create_async_callback(Box::new(move |lua, args| { let args = match A::from_lua_multi(args, lua) { - Ok(x) => x, - Err(e) => return future::err(e).boxed_local(), + Ok(args) => args, + Err(e) => return Box::pin(future::err(e)), }; - func(lua, args) - .and_then(move |x| future::ready(x.to_lua_multi(lua))) - .boxed_local() + Box::pin(func(lua, args).and_then(move |ret| future::ready(ret.to_lua_multi(lua)))) })) } @@ -1420,8 +1417,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> { R: FromLuaMulti<'lua> + 'fut, { match self.into_function() { - Ok(f) => f.call_async(args), - Err(e) => Box::pin(futures_util::future::err(e)), + Ok(func) => func.call_async(args), + Err(e) => Box::pin(future::err(e)), } } @@ -1742,7 +1739,7 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { MR: 'static + Future>, { Box::new(move |lua, mut args| { - let fut = || { + let fut_res = || { if let Some(front) = args.pop_front() { let userdata = AnyUserData::from_lua(front, lua)?; let userdata = userdata.borrow::()?.clone(); @@ -1755,11 +1752,9 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { }) } }; - match fut() { - Ok(f) => f - .and_then(move |fr| future::ready(fr.to_lua_multi(lua))) - .boxed_local(), - Err(e) => future::err(e).boxed_local(), + match fut_res() { + Ok(fut) => Box::pin(fut.and_then(move |ret| future::ready(ret.to_lua_multi(lua)))), + Err(e) => Box::pin(future::err(e)), } }) } @@ -1798,12 +1793,10 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { { Box::new(move |lua, args| { let args = match A::from_lua_multi(args, lua) { - Ok(x) => x, - Err(e) => return future::err(e).boxed_local(), + Ok(args) => args, + Err(e) => return Box::pin(future::err(e)), }; - function(lua, args) - .and_then(move |x| future::ready(x.to_lua_multi(lua))) - .boxed_local() + Box::pin(function(lua, args).and_then(move |ret| future::ready(ret.to_lua_multi(lua)))) }) } } diff --git a/src/table.rs b/src/table.rs index f0eecac..f8a365f 100644 --- a/src/table.rs +++ b/src/table.rs @@ -9,10 +9,7 @@ use crate::util::{assert_stack, protect_lua, protect_lua_closure, StackGuard}; use crate::value::{FromLua, FromLuaMulti, Nil, ToLua, ToLuaMulti, Value}; #[cfg(feature = "async")] -use { - futures_core::future::LocalBoxFuture, - futures_util::future::{self, FutureExt}, -}; +use {futures_core::future::LocalBoxFuture, futures_util::future}; /// Handle to an internal Lua table. #[derive(Clone, Debug)] @@ -145,23 +142,6 @@ impl<'lua> Table<'lua> { /// This function is deprecated since 0.3.1 in favor of [`call_method`] /// in the `TableExt` trait. /// - /// # Examples - /// - /// Execute the table method with name "concat": - /// - /// ``` - /// # use mlua::{Lua, Result, Table}; - /// # fn main() -> Result<()> { - /// # let lua = Lua::new(); - /// # let object = lua.create_table()?; - /// # let concat = lua.create_function(|_, (_, a, b): (Table, String, String)| Ok(a + &b))?; - /// # object.set("concat", concat)?; - /// // simiar to: object:concat("param1", "param2") - /// object.call("concat", ("param1", "param2"))?; - /// # Ok(()) - /// # } - /// ``` - /// /// This might invoke the `__index` metamethod. /// /// [`call_method`]: trait.TableExt.html#tymethod.call_method @@ -596,7 +576,7 @@ impl<'lua> TableExt<'lua> for Table<'lua> { let lua = self.0.lua; let mut args = match args.to_lua_multi(lua) { Ok(args) => args, - Err(e) => return future::err(e).boxed_local(), + Err(e) => return Box::pin(future::err(e)), }; args.push_front(Value::Table(self.clone())); self.call_async_function(key, args) @@ -610,11 +590,10 @@ impl<'lua> TableExt<'lua> for Table<'lua> { A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua> + 'fut, { - let func = match self.get::<_, Function>(key) { - Ok(f) => f, - Err(e) => return future::err(e).boxed_local(), - }; - func.call_async(args) + match self.get::<_, Function>(key) { + Ok(func) => func.call_async(args), + Err(e) => Box::pin(future::err(e)), + } } }