美文网首页
[async_std]--1.2--std::future an

[async_std]--1.2--std::future an

作者: buddyCoder | 来源:发表于2020-03-11 16:27 被阅读0次

std::future and futures-rs

Rust has two kinds of types commonly referred to as Future:
Rust通用的Future有两种类型:

  • the first is std::future::Future from Rust’s standard library.
  • the second is futures::future::Future from the futures-rs crate.
    第一个是std::future:: future来自Rust的标准库。
    第二个是futures::future:: future来自于futuresr crate

The future defined in the futures-rs crate was the original implementation of the type. To enable the async/await syntax, the core Future trait was moved into Rust’s standard library and became std::future::Future. In some sense, the std::future::Future can be seen as a minimal subset of futures::future::Future.
在futuresrs crate中定义的future类型的原始实现。为了支持async/await语法,核心的Future trait被移到了Rust的标准库中,变成了std::Future::Future。在某种意义上,std::future::future可以看作是future::future::future的最小子集。

It is critical to understand the difference between std::future::Future and futures::future::Future, and the approach that async-std takes towards them. In itself, std::future::Future is not something you want to interact with as a user—except by calling .await on it. The inner workings of std::future::Future are mostly of interest to people implementing Future. Make no mistake—this is very useful! Most of the functionality that used to be defined on Future itself has been moved to an extension trait called FuturesExt. From this information, you might be able to infer that the futures library serves as an extension to the core Rust async features.
理解std::future::future和futures::future::future之间的区别以及 async-std 对它们采取的方法是至关重要的。就其本身而言,std::future::future不是您希望作为用户与之交互的东西——除非调用.await。std::future::future的内部工作原理主要是实现future的人感兴趣的。不要出错——这是非常有用的!过去在Future上定义的大部分功能现在都转移到了一个名为FuturesExt的扩展特性上。从这些信息中,您可以推断出futures库是作为核心Rust异步特性的扩展。

In the same tradition as futures, async-std re-exports the core std::future::Future type. You can actively opt into the extensions provided by the futures crate by adding it to your Cargo.toml and importing FuturesExt.

在与futures相同的传承中,async-std 重新导出了核心 std::future:: future 类型。你可以通过将the futures crate 添加到你的货物中,积极选择加入futures crate提供的 Cargo.toml 和导入FuturesExt。

Interfaces and Stability

async-std aims to be a stable and reliable library, at the level of the Rust standard library. This also means that we don't rely on the futures library for our interface. Yet, we appreciate that many users have come to like the conveniences that futures-rs brings. For that reason, async-std implements all futures traits for its types.
async-std的目标是在Rust标准库的层次上成为一个稳定可靠的库。这也意味着我们的接口不依赖于futures库。然而,我们意识到许多用户已经开始喜欢futures-rs 带来的便利。因此,async std实现了其类型的所有futures特性。

Luckily, the approach from above gives you full flexibility. If you care about stability a lot, you can just use async-std as is. If you prefer the futures library interfaces, you link those in. Both uses are first class.
幸运的是,上面的方法给了你充分的灵活性。如果你非常关心稳定性,你可以直接使用async std。如果您喜欢futures库接口,可以将它们链接到中。两种用途都是一流的。

async_std::future

There’s some support functions that we see as important for working with futures of any kind. These can be found in the async_std::future module and are covered by our stability guarantees.
我们认为,有一些支持功能对于处理任何类型的futures 都很重要。这些都可以在我们的稳定版本async_std::future模块中找到,已经涵盖所有。

Streams and Read/Write/Seek/BufRead traits

Due to limitations of the Rust compiler, those are currently implemented in async_std, but cannot be implemented by users themselves.

由于Rust编译器的局限性,它们目前是用async-std实现的,但不能由用户自己实现。

相关文章

网友评论

      本文标题:[async_std]--1.2--std::future an

      本文链接:https://www.haomeiwen.com/subject/qnzcjhtx.html