using async_trait in tuple generic param, error: lifetime may not live long enough
- Dominant language
- Rust
- Stars
- 2.2k
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
hi, here is the code, and will compile for `(A,)`, but can't compile for `(A, B)`.
here is the code in the [playgoround](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=faa1b1c11c55001253a1f993e8af2e17)
```rust
use async_trait::async_trait;
struct Text;
#[async_trait]
trait FromText<'r> {
type Output;
async fn parse(text: &'r Text) -> Self::Output;
}
// can compile for (A,)
#[async_trait]
impl<'r, A> FromText<'r> for (A,)
where
A: FromText<'r>,
{
type Output = (A::Output,);
async fn parse(text: &'r Text) -> Self::Output {
let a = A::parse(text).await;
(a,)
}
}
// can't compile for (A, B)
#[async_trait]
impl<'r, A, B> FromText<'r> for (A, B)
where
A: FromText<'r>,
B: FromText<'r>,
A::Output: Send,
B::Output: Send,
{
type Output = (A::Output, B::Output);
async fn parse(text: &'r Text) -> Self::Output {
let a = A::parse(text).await;
let b = B::parse(text).await;
(a, b)
}
}
```
the error message:
```
ompiling playground v0.0.1 (/playground)
error: lifetime may not live long enough
--> src/lib.rs:37:52
|
28 | impl<'r, A, B> FromText<'r> for (A, B)
| -- lifetime `'r` defined here
...
37 | async fn parse(text: &'r Text) -> Self::Output {
| ____________________________________________________^
38 | | let a = A::parse(text).await;
39 | | let b = B::parse(text).await;
40 | | (a, b)
41 | | }
| |_____^ cast requires that `'r` must outlive `'static`
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.