Add MaybeSend bound to async methods on ObjectLike trait (sealed)

This commit is contained in:
Alex Orlenko
2025-07-12 12:45:36 +01:00
parent 06c3bd9d69
commit 7afbf74128
3 changed files with 50 additions and 20 deletions
+18 -7
View File
@@ -13,7 +13,10 @@ use crate::util::{assert_stack, check_stack, get_metatable_ptr, StackGuard};
use crate::value::{Nil, Value};
#[cfg(feature = "async")]
use futures_util::future::{self, Either, Future};
use {
crate::types::MaybeSend,
futures_util::future::{self, Either, Future},
};
#[cfg(feature = "serde")]
use {
@@ -889,9 +892,9 @@ impl ObjectLike for Table {
#[cfg(feature = "async")]
#[inline]
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
Function(self.0.copy()).call_async(args)
}
@@ -905,9 +908,13 @@ impl ObjectLike for Table {
}
#[cfg(feature = "async")]
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
self.call_async_function(name, (self, args))
}
@@ -925,9 +932,13 @@ impl ObjectLike for Table {
#[cfg(feature = "async")]
#[inline]
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
match self.get(name) {
Ok(Value::Function(func)) => Either::Left(func.call_async(args)),
+14 -6
View File
@@ -162,9 +162,9 @@ pub trait ObjectLike: Sealed {
/// arguments.
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti;
R: FromLuaMulti + MaybeSend;
/// Gets the function associated to key `name` from the object and calls it,
/// passing the object itself along with `args` as function arguments.
@@ -178,9 +178,13 @@ pub trait ObjectLike: Sealed {
/// This might invoke the `__index` metamethod.
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti;
R: FromLuaMulti + MaybeSend;
/// Gets the function associated to key `name` from the object and calls it,
/// passing `args` as function arguments.
@@ -196,9 +200,13 @@ pub trait ObjectLike: Sealed {
/// This might invoke the `__index` metamethod.
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti;
R: FromLuaMulti + MaybeSend;
/// Converts the object to a string in a human-readable format.
///
+18 -7
View File
@@ -8,7 +8,10 @@ use crate::value::Value;
use crate::Function;
#[cfg(feature = "async")]
use futures_util::future::{self, Either, Future};
use {
crate::types::MaybeSend,
futures_util::future::{self, Either, Future},
};
impl ObjectLike for AnyUserData {
#[inline]
@@ -35,9 +38,9 @@ impl ObjectLike for AnyUserData {
#[cfg(feature = "async")]
#[inline]
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
Function(self.0.copy()).call_async(args)
}
@@ -51,9 +54,13 @@ impl ObjectLike for AnyUserData {
}
#[cfg(feature = "async")]
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_method<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
self.call_async_function(name, (self, args))
}
@@ -72,9 +79,13 @@ impl ObjectLike for AnyUserData {
}
#[cfg(feature = "async")]
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
fn call_async_function<R>(
&self,
name: &str,
args: impl IntoLuaMulti,
) -> impl Future<Output = Result<R>> + MaybeSend
where
R: FromLuaMulti,
R: FromLuaMulti + MaybeSend,
{
match self.get(name) {
Ok(Value::Function(func)) => Either::Left(func.call_async(args)),