-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add macro expand tests * Include cargo-expand in test setup
- Loading branch information
Showing
19 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use async_recursion::async_recursion; | ||
#[must_use] | ||
pub fn n( | ||
x: i32, | ||
) -> ::core::pin::Pin< | ||
Box<dyn ::core::future::Future<Output = i32> + ::core::marker::Send>, | ||
> { | ||
Box::pin(async move { x }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use async_recursion::async_recursion; | ||
|
||
#[async_recursion] | ||
pub async fn n(x: i32) -> i32 { | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use async_recursion::async_recursion; | ||
#[must_use] | ||
fn fib( | ||
n: u32, | ||
) -> ::core::pin::Pin< | ||
Box<dyn ::core::future::Future<Output = u64> + ::core::marker::Send>, | ||
> { | ||
Box::pin(async move { | ||
match n { | ||
0 => { | ||
::std::rt::begin_panic("zero is not a valid argument to fib()!"); | ||
} | ||
1 | 2 => 1, | ||
3 => 2, | ||
_ => fib(n - 1).await + fib(n - 2).await, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use async_recursion::async_recursion; | ||
|
||
#[async_recursion] | ||
async fn fib(n: u32) -> u64 { | ||
match n { | ||
0 => panic!("zero is not a valid argument to fib()!"), | ||
1 | 2 => 1, | ||
3 => 2, | ||
_ => fib(n - 1).await + fib(n - 2).await, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use async_recursion::async_recursion; | ||
#[must_use] | ||
pub fn generic_parameter<'async_recursion, S: Marker + Send>( | ||
mut x: S, | ||
) -> ::core::pin::Pin< | ||
Box< | ||
dyn ::core::future::Future< | ||
Output = u64, | ||
> + 'async_recursion + ::core::marker::Send, | ||
>, | ||
> | ||
where | ||
S: 'async_recursion, | ||
{ | ||
Box::pin(async move { if x.descend() { generic_parameter(x).await } else { 0 } }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use async_recursion::async_recursion; | ||
|
||
#[async_recursion] | ||
pub async fn generic_parameter<S: Marker + Send>(mut x: S) -> u64 { | ||
if x.descend() { | ||
generic_parameter(x).await | ||
} else { | ||
0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use async_recursion::async_recursion; | ||
#[must_use] | ||
pub fn generic_parameter_no_send<'async_recursion, T>( | ||
x: T, | ||
y: u64, | ||
) -> ::core::pin::Pin<Box<dyn ::core::future::Future<Output = u64> + 'async_recursion>> | ||
where | ||
T: 'async_recursion, | ||
{ | ||
Box::pin(async move { | ||
if y > 0 { generic_parameter_no_send(x, y - 1).await } else { 111 } | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use async_recursion::async_recursion; | ||
|
||
#[async_recursion(?Send)] | ||
pub async fn generic_parameter_no_send<T>(x: T, y: u64) -> u64 { | ||
if y > 0 { | ||
generic_parameter_no_send(x, y - 1).await | ||
} else { | ||
111 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use async_recursion::async_recursion; | ||
#[must_use] | ||
fn contains_value_2<'a, 'b, 'async_recursion, T: PartialEq>( | ||
value: &'b T, | ||
node: &'b Node<'a, T>, | ||
) -> ::core::pin::Pin<Box<dyn ::core::future::Future<Output = bool> + 'async_recursion>> | ||
where | ||
T: 'async_recursion, | ||
'b: 'async_recursion, | ||
{ | ||
Box::pin(async move { contains_value(value, node).await }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use async_recursion::async_recursion; | ||
|
||
#[async_recursion(?Send)] | ||
async fn contains_value_2<'a, 'b, T: PartialEq>(value: &'b T, node: &'b Node<'a, T>) -> bool { | ||
contains_value(value, node).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use async_recursion::async_recursion; | ||
struct Node<'a, T> { | ||
ptr: &'a T, | ||
} | ||
#[must_use] | ||
fn contains_value<'a, 'life0, 'life1, 'async_recursion, T: PartialEq>( | ||
value: &'life0 T, | ||
node: &'life1 Node<'a, T>, | ||
) -> ::core::pin::Pin<Box<dyn ::core::future::Future<Output = bool> + 'async_recursion>> | ||
where | ||
T: 'async_recursion, | ||
'life0: 'async_recursion, | ||
'life1: 'async_recursion, | ||
{ | ||
Box::pin(async move { if &node.ptr == value { true } else { false } }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use async_recursion::async_recursion; | ||
|
||
struct Node<'a, T> { | ||
ptr: &'a T, | ||
} | ||
|
||
#[async_recursion(?Send)] | ||
async fn contains_value<'a, T: PartialEq>(value: &T, node: &Node<'a, T>) -> bool { | ||
if &node.ptr == value { | ||
true | ||
} else { | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#[must_use] | ||
fn owned<'life0, 'async_recursion, F>( | ||
param: usize, | ||
f: &'life0 F, | ||
) -> ::core::pin::Pin< | ||
Box< | ||
dyn ::core::future::Future<Output = ()> + 'async_recursion + ::core::marker::Send, | ||
>, | ||
> | ||
where | ||
F: Fn(usize) + Sync + Send, | ||
F: 'async_recursion, | ||
'life0: 'async_recursion, | ||
{ | ||
Box::pin(async move { | ||
f(param); | ||
}) | ||
} | ||
#[must_use] | ||
fn by_ref<'life0, 'life1, 'async_recursion, F>( | ||
param: &'life0 usize, | ||
f: &'life1 F, | ||
) -> ::core::pin::Pin< | ||
Box< | ||
dyn ::core::future::Future<Output = ()> + 'async_recursion + ::core::marker::Send, | ||
>, | ||
> | ||
where | ||
F: Fn(&usize) + Sync + Send, | ||
F: 'async_recursion, | ||
'life0: 'async_recursion, | ||
'life1: 'async_recursion, | ||
{ | ||
Box::pin(async move { | ||
f(param); | ||
}) | ||
} | ||
#[must_use] | ||
fn by_ref_mut<'life0, 'life1, 'async_recursion, F>( | ||
param: &'life0 mut usize, | ||
f: &'life1 F, | ||
) -> ::core::pin::Pin< | ||
Box< | ||
dyn ::core::future::Future<Output = ()> + 'async_recursion + ::core::marker::Send, | ||
>, | ||
> | ||
where | ||
F: Fn(&mut usize) + Sync + Send, | ||
F: 'async_recursion, | ||
'life0: 'async_recursion, | ||
'life1: 'async_recursion, | ||
{ | ||
Box::pin(async move { | ||
f(param); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
macro_rules! recurse { | ||
($name:ident, $param:ty) => { | ||
#[::async_recursion::async_recursion] | ||
async fn $name<F>(param: $param, f: &F) | ||
where | ||
F: Fn($param) + Sync + Send, | ||
{ | ||
f(param); | ||
} | ||
}; | ||
} | ||
|
||
recurse!(owned, usize); | ||
recurse!(by_ref, &usize); | ||
recurse!(by_ref_mut, &mut usize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use async_recursion::async_recursion; | ||
struct S; | ||
impl S { | ||
#[must_use] | ||
pub fn all_of_the_above<'a, 'b, 'life0, 'life1, 'life_self, 'async_recursion, S, T>( | ||
&'life_self self, | ||
_x: &'life0 S, | ||
_y: &'b T, | ||
_w: S, | ||
_z: T, | ||
_p: &'life1 usize, | ||
_q: &'a u64, | ||
) -> ::core::pin::Pin< | ||
Box< | ||
dyn ::core::future::Future< | ||
Output = (), | ||
> + 'async_recursion + ::core::marker::Send, | ||
>, | ||
> | ||
where | ||
S: 'async_recursion, | ||
T: 'async_recursion, | ||
'life0: 'async_recursion, | ||
'b: 'async_recursion, | ||
'life1: 'async_recursion, | ||
'a: 'async_recursion, | ||
'life_self: 'async_recursion, | ||
{ | ||
Box::pin(async move {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use async_recursion::async_recursion; | ||
|
||
struct S; | ||
|
||
impl S { | ||
#[async_recursion] | ||
pub async fn all_of_the_above<'a, 'b, S, T>( | ||
&self, | ||
// Some references with / without lifetimes to generic parameters | ||
_x: &S, | ||
_y: &'b T, | ||
// Some generic parameters passed by value | ||
_w: S, | ||
_z: T, | ||
// A reference to a concrete type without a lifetime | ||
_p: &usize, | ||
// A reference to a concrete type with a lifetime | ||
_q: &'a u64, | ||
) { | ||
} | ||
} |