Hi! I'm trying to make a trait method return a future. The future might need to access member variables, and I can't get it to work.
#![feature(type_alias_impl_trait)]
use std::future::*;
struct Foo(i32);
// Outside of a trait this all works fine
type T<'a> = impl Future<Output=i32> + 'a;
impl Foo {
async fn ref_async(self: &Self) -> i32 {
self.0
}
// All these variants are ok.
// fn blah<'a>(self: &'a Self) -> impl Future<Output=i32> + 'a {
// fn blah<'a>(self: &'a Self) -> T<'a> {
fn blah(self: &Self) -> T<'_> {
self.ref_async()
}
}
But everything goes a bit hairbrained in a trait:
trait SomeTrait {
type TT;
fn blah(self: &Self) -> Self::TT;
}
impl SomeTrait for Foo {
type TT<'a> = impl Future<Output=i32> + 'a;
fn blah<'a>(self: &'a Self) -> Self::TT<'a> { // <- Errors..
self.ref_async()
}
}
I can't seem to figure out how to associate the lifetime of my self object with the return value. Does this need GAT or something?