6

Rust 中的函数式语言功能:迭代器与闭包

 2 years ago
source link: https://kaisery.github.io/trpl-zh-cn/ch13-00-functional-features.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Rust 程序设计语言 简体中文版

Rust 中的函数式语言功能:迭代器与闭包

ch13-00-functional-features.md
commit 1fedfc4b96c2017f64ecfcf41a0a07e2e815f24f

Rust 的设计灵感来源于很多现存的语言和技术。其中一个显著的影响就是 函数式编程functional programming)。函数式编程风格通常包含将函数作为参数值或其他函数的返回值、将函数赋值给变量以供之后执行等等。

本章我们不会讨论函数式编程是或不是什么的问题,而是展示 Rust 的一些在功能上与其他被认为是函数式语言类似的特性。

更具体的,我们将要涉及:

  • 闭包Closures),一个可以储存在变量里的类似函数的结构
  • 迭代器Iterators),一种处理元素序列的方式
  • 如何使用这些功能来改进第十二章的 I/O 项目。
  • 这两个功能的性能。(剧透警告: 他们的速度超乎你的想象!)

还有其它受函数式风格影响的 Rust 功能,比如模式匹配和枚举,这些已经在其他章节中讲到过了。掌握闭包和迭代器则是编写符合语言风格的高性能 Rust 代码的重要一环,所以我们将专门用一整章来讲解他们。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK