Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

常见编程概念

Common Programming Concepts

本章介绍几乎所有编程语言中都会出现的概念,以及它们在 Rust 中是如何工作的。许多编程语言的核心都有很多共同之处。本章介绍的概念都不是 Rust 特有的,但我们将在 Rust 的背景下讨论它们,并解释使用它们的约定。

This chapter covers concepts that appear in almost every programming language and how they work in Rust. Many programming languages have much in common at their core. None of the concepts presented in this chapter are unique to Rust, but we’ll discuss them in the context of Rust and explain the conventions around using them.

具体来说,你将学习变量、基本类型、函数、注释和控制流。这些基础知识将出现在每个 Rust 程序中,及早学习它们将为你打下坚实的基础。

Specifically, you’ll learn about variables, basic types, functions, comments, and control flow. These foundations will be in every Rust program, and learning them early will give you a strong core to start from.

关键字

Keywords

Rust 语言有一组保留给语言本身使用的“关键字”(keywords),就像其他语言一样。请记住,你不能将这些词用作变量或函数的名称。大多数关键字具有特殊含义,你将使用它们在 Rust 程序中执行各种任务;少数关键字目前没有关联的功能,但已为将来可能添加到 Rust 的功能而保留。你可以在 附录 A 中找到关键字列表。

The Rust language has a set of keywords that are reserved for use by the language only, much as in other languages. Keep in mind that you cannot use these words as names of variables or functions. Most of the keywords have special meanings, and you’ll be using them to do various tasks in your Rust programs; a few have no current functionality associated with them but have been reserved for functionality that might be added to Rust in the future. You can find the list of the keywords in Appendix A.