1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//!
//! # orion-async: 消除异步函数内部的本地变量必须支持Send Trait的约束,提升性能.
//! # orion-async: Eliminate this constraint - the local variables of asynchronous functions must implement Send Trait
//!
//! 异步运行时框架的调度接口都会要求Future支持Send Trait,但现有编译器的实现中,
//! 如果异步函数内部使用了不支持Send Trait的变量类型,则其生成Future不支持Send.
//!
//! 理想情况下异步函数生成的Future是否支持Send Trait应该仅有输入参数类型来决定,
//! 在编译器未支持的情况下,可使用orion-async来解决,可以写更高效的异步代码.
//!
//! # Examples
//!
//! ```rust
//! use std::rc::Rc;
//! use std::future::Future;
//!
//! #[orion_async::future(body_send=true)]
//! async fn foo() {
//! let val = Rc::new(100);
//! bar(*val).await;
//! }
//! async fn bar(val: i32) {
//! }
//! fn test_send_future<T: Future + Send>(t: T) {
//! }
//!
//! test_send_future(foo());
//!
//! ```
//!
//! 可用于struct的方法
//!
//! ```rust
//! use std::rc::Rc;
//! use std::future::Future;
//!
//! struct Foo;
//!
//! impl Foo {
//! #[orion_async::future(body_send=true)]
//! async fn foo(self) -> i32 {
//! let val = Rc::new(100);
//! self.bar(*val).await
//! }
//! async fn bar(&self, val: i32) -> i32 {
//! val + 100
//! }
//! }
//! fn test_send_future<T: Future + Send>(t: T) {
//! }
//!
//! let foo = Foo;
//! test_send_future(foo.foo());
//! ```
//!
use ;
use ;
use Pin;
pub use ;
unsafe