我似乎不明白这里的编译器错误消息。对于以下代码片段
use std::pin::Pin;
use std::future::Future;
fn give_future<'a>(x : &'a i32) -> Pin<impl Future<Output=&'a i32> + 'a> {
Box::pin(async move { x })
}
Run Code Online (Sandbox Code Playgroud)
它说以下内容
error[E0277]: `[async block@src/lib.rs]` cannot be unpinned
--> src/lib.rs:7:47
|
| fn give_future<'a>(x : &'a i32) -> Pin<impl Future<Output=&'a i32> + 'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `[async block@src/lib.rs]`
|
= note: consider using the `pin!` macro
consider using `Box::pin` if you need to access the pinned value outside of the current scope
= note: required for `Box<[async block@src/lib.rs]>` to implement `Future`
For more information about this error, try `rustc --explain E0277`.
Run Code Online (Sandbox Code Playgroud)
据我了解,Pinx<Box<impl Future>>返回为Pin<impl Future>. 为什么编译器不直接这么说呢?
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |