版本:
铁锈-版本
每晚(95a3a7277 2022-10-31)
错误:
error: non-defining opaque type use in defining scope
--> src/main.rs:22:9
|
22 | / async move {
23 | | Some(self.name)
24 | | }
| |_________^ lifetime `'a` is part of concrete type but not used in parameter list of the `impl Trait` type alias代码:
#![feature(associated_type_defaults)]
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
use std::future::Future;
pub trait KvIterator {
type NextFuture<'b>: Future<Output = Option<&'b [u8]>>
where
Self: 'b;
fn next<'s>(&'s mut self) -> Self::NextFuture<'s>;
//fn get_name<'s>(&'s self) -> &'s [u8];
}
struct Person<'a> {
name: &'a [u8],
}
impl<'a> KvIterator for Person<'a> {
type NextFuture<'b>
where
Self: 'b,
= impl Future<Output = Option<&'b [u8]>>; //
fn next<'s>(&'s mut self) -> Self::NextFuture<'s> {
async move { Some(self.name) }
}
// fn get_name<'s>(&'s self) -> &'s [u8] {
// self.name
// }
}
fn main() {
// Person(Self) outlive 'a
{
let mut p = Person { name: b"" };
{
let name = vec![97, 98, 99];
p.name = name.as_slice();
// let name1 = p.next().await;
//let name1 = p.get_name();
//dbg!(name1);
}
}
}游乐场:
发布于 2022-11-16 02:56:29
异步块代码试图捕获(将extern变量移动到闭包内部)使用'a,所以应该删除关键字'move‘声明生存期的self.name,如下所示:
async {
Some(self.name)
}https://stackoverflow.com/questions/74441311
复制相似问题