相关疑难解决方法(0)

std :: ops :: Add或core :: ops :: Add?

这两个特征(std :: ops :: Add,core :: ops :: Add)提供相同的功能,并且它们都使用相同的示例(两者都使用std::ops::Add).他们的实施者有所不同.

应该默认使用std::ops::Add吗?为什么两者相对而存在呢?

standard-library rust

10
推荐指数
2
解决办法
1697
查看次数

`alloc :: rc :: Rc`和`std :: rc :: Rc`有什么区别?

我很好奇这两个模块在实践中有区别吗?如果没有,为什么这两个重复呢?

module rust

3
推荐指数
1
解决办法
88
查看次数

如何在不使用任何外部依赖项的情况下执行 async/await 函数?

我正在尝试创建最简单的示例,async fn hello()最终可以打印出Hello World!. 这应该在没有任何外部依赖的情况下发生tokio,就像普通的 Rust 和std. 如果我们可以在不使用unsafe.

#![feature(async_await)]

async fn hello() {
    println!("Hello, World!");
}

fn main() {
    let task = hello();

    // Something beautiful happens here, and `Hello, World!` is printed on screen.
}
Run Code Online (Sandbox Code Playgroud)
  • 我知道async/await这仍然是一个夜间功能,在可预见的未来可能会发生变化。
  • 我知道有很多Future实现,我知道tokio.
  • 我只是试图让自己了解标准库期货的内部运作方式。

我无助、笨拙的努力

我模糊的理解是,首先,我需要完成Pin任务。所以我继续前进

let pinned_task = Pin::new(&mut task);
Run Code Online (Sandbox Code Playgroud)

the trait `std::marker::Unpin` is not implemented for `std::future::GenFuture<[static generator@src/main.rs:7:18: 9:2 {}]>`
Run Code Online (Sandbox Code Playgroud)

所以我想,当然,我可能需要Box它,所以我确定它不会在内存中移动。有点令人惊讶的是,我得到了同样的错误。

到目前为止我能得到的是 …

asynchronous future rust

3
推荐指数
1
解决办法
1607
查看次数

标签 统计

rust ×3

asynchronous ×1

future ×1

module ×1

standard-library ×1