Skip to content

Commit 7afbf74

Browse files
committed
Add MaybeSend bound to async methods on ObjectLike trait (sealed)
1 parent 06c3bd9 commit 7afbf74

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

src/table.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use crate::util::{assert_stack, check_stack, get_metatable_ptr, StackGuard};
1313
use crate::value::{Nil, Value};
1414

1515
#[cfg(feature = "async")]
16-
use futures_util::future::{self, Either, Future};
16+
use {
17+
crate::types::MaybeSend,
18+
futures_util::future::{self, Either, Future},
19+
};
1720

1821
#[cfg(feature = "serde")]
1922
use {
@@ -889,9 +892,9 @@ impl ObjectLike for Table {
889892

890893
#[cfg(feature = "async")]
891894
#[inline]
892-
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
895+
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
893896
where
894-
R: FromLuaMulti,
897+
R: FromLuaMulti + MaybeSend,
895898
{
896899
Function(self.0.copy()).call_async(args)
897900
}
@@ -905,9 +908,13 @@ impl ObjectLike for Table {
905908
}
906909

907910
#[cfg(feature = "async")]
908-
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
911+
fn call_async_method<R>(
912+
&self,
913+
name: &str,
914+
args: impl IntoLuaMulti,
915+
) -> impl Future<Output = Result<R>> + MaybeSend
909916
where
910-
R: FromLuaMulti,
917+
R: FromLuaMulti + MaybeSend,
911918
{
912919
self.call_async_function(name, (self, args))
913920
}
@@ -925,9 +932,13 @@ impl ObjectLike for Table {
925932

926933
#[cfg(feature = "async")]
927934
#[inline]
928-
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
935+
fn call_async_function<R>(
936+
&self,
937+
name: &str,
938+
args: impl IntoLuaMulti,
939+
) -> impl Future<Output = Result<R>> + MaybeSend
929940
where
930-
R: FromLuaMulti,
941+
R: FromLuaMulti + MaybeSend,
931942
{
932943
match self.get(name) {
933944
Ok(Value::Function(func)) => Either::Left(func.call_async(args)),

src/traits.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ pub trait ObjectLike: Sealed {
162162
/// arguments.
163163
#[cfg(feature = "async")]
164164
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
165-
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
165+
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
166166
where
167-
R: FromLuaMulti;
167+
R: FromLuaMulti + MaybeSend;
168168

169169
/// Gets the function associated to key `name` from the object and calls it,
170170
/// passing the object itself along with `args` as function arguments.
@@ -178,9 +178,13 @@ pub trait ObjectLike: Sealed {
178178
/// This might invoke the `__index` metamethod.
179179
#[cfg(feature = "async")]
180180
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
181-
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
181+
fn call_async_method<R>(
182+
&self,
183+
name: &str,
184+
args: impl IntoLuaMulti,
185+
) -> impl Future<Output = Result<R>> + MaybeSend
182186
where
183-
R: FromLuaMulti;
187+
R: FromLuaMulti + MaybeSend;
184188

185189
/// Gets the function associated to key `name` from the object and calls it,
186190
/// passing `args` as function arguments.
@@ -196,9 +200,13 @@ pub trait ObjectLike: Sealed {
196200
/// This might invoke the `__index` metamethod.
197201
#[cfg(feature = "async")]
198202
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
199-
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
203+
fn call_async_function<R>(
204+
&self,
205+
name: &str,
206+
args: impl IntoLuaMulti,
207+
) -> impl Future<Output = Result<R>> + MaybeSend
200208
where
201-
R: FromLuaMulti;
209+
R: FromLuaMulti + MaybeSend;
202210

203211
/// Converts the object to a string in a human-readable format.
204212
///

src/userdata/object.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::value::Value;
88
use crate::Function;
99

1010
#[cfg(feature = "async")]
11-
use futures_util::future::{self, Either, Future};
11+
use {
12+
crate::types::MaybeSend,
13+
futures_util::future::{self, Either, Future},
14+
};
1215

1316
impl ObjectLike for AnyUserData {
1417
#[inline]
@@ -35,9 +38,9 @@ impl ObjectLike for AnyUserData {
3538

3639
#[cfg(feature = "async")]
3740
#[inline]
38-
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
41+
fn call_async<R>(&self, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>> + MaybeSend
3942
where
40-
R: FromLuaMulti,
43+
R: FromLuaMulti + MaybeSend,
4144
{
4245
Function(self.0.copy()).call_async(args)
4346
}
@@ -51,9 +54,13 @@ impl ObjectLike for AnyUserData {
5154
}
5255

5356
#[cfg(feature = "async")]
54-
fn call_async_method<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
57+
fn call_async_method<R>(
58+
&self,
59+
name: &str,
60+
args: impl IntoLuaMulti,
61+
) -> impl Future<Output = Result<R>> + MaybeSend
5562
where
56-
R: FromLuaMulti,
63+
R: FromLuaMulti + MaybeSend,
5764
{
5865
self.call_async_function(name, (self, args))
5966
}
@@ -72,9 +79,13 @@ impl ObjectLike for AnyUserData {
7279
}
7380

7481
#[cfg(feature = "async")]
75-
fn call_async_function<R>(&self, name: &str, args: impl IntoLuaMulti) -> impl Future<Output = Result<R>>
82+
fn call_async_function<R>(
83+
&self,
84+
name: &str,
85+
args: impl IntoLuaMulti,
86+
) -> impl Future<Output = Result<R>> + MaybeSend
7687
where
77-
R: FromLuaMulti,
88+
R: FromLuaMulti + MaybeSend,
7889
{
7990
match self.get(name) {
8091
Ok(Value::Function(func)) => Either::Left(func.call_async(args)),

0 commit comments

Comments
 (0)