mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Update anchor
This commit is contained in:
@@ -242,7 +242,7 @@ future 组合器的最大优势在于它们能保持操作的异步性。在与
|
||||
|
||||
[_Zero-cost futures in Rust_]: https://aturon.github.io/blog/2016/08/11/futures/
|
||||
|
||||
##### 缺点
|
||||
##### 缺点 {#drawbacks}
|
||||
|
||||
虽然 future 组合器能够编写出非常高效的代码,但在某些情况下,由于类型系统和基于闭包的接口,它们可能变得难以使用。例如,考虑如下代码:
|
||||
|
||||
@@ -300,7 +300,7 @@ async fn example(min_len: usize) -> String {
|
||||
|
||||
([Try it on the playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d93c28509a1c67661f31ff820281d434))
|
||||
|
||||
此函数直接转换自[上文](#####缺点)中使用组合函数的 `example` 函数。通过使用 `.await` 运算符,我们无需任何闭包或者 `Either` 类型就可以直接获取 future 的值。于是我们就可以像写普通的同步代码一样编写代码,只不过 _这实际上是异步代码_。
|
||||
此函数直接转换自[上文](#drawbacks)中使用组合函数的 `example` 函数。通过使用 `.await` 运算符,我们无需任何闭包或者 `Either` 类型就可以直接获取 future 的值。于是我们就可以像写普通的同步代码一样编写代码,只不过 _这实际上是异步代码_。
|
||||
|
||||
#### 状态机转换
|
||||
|
||||
|
||||
Reference in New Issue
Block a user