The Rust Programming Language (Covers Rust 2018)

Steve Klabnik, Carol Nichols

出版时间

2019-08-13

ISBN

9781718500440

评分

★★★★★
书籍介绍
The official book on the Rust programming language, written by the Rust development team at the Mozilla Foundation, fully updated for Rust 2018. The Rust Programming Language is the official, definitive guide to Rust, a hugely popular, community-supported programming language. This is the second edition of the improved version of the free online Rust book, so well-loved in the Rust community that it is simply referred to as "the Book". Programmers love Rust because it allows them to write powerful code efficiently, without the risk of crashes and errors common in languages like C and C++. This book will show readers how to use Rust's robust type system to keep programs memory-safe and speedy, and make the most of the Cargo package manager that brings the pieces of a program together. The reader will learn all about Rust's ownership rules, which lie at the heart of Rust's reliability and crash-resistant compiling. The Rust Programming Language covers everything from basic concepts like variable bindings, control flow, functions, and error handling, to more advanced topics, such as crates, generics, concurrency, and the nitty gritty of Rust's type system. With improved organization, hands-on features, and a more tutorial-oriented style, this version offers a vast improvement over the original. The second edition also provides an entirely new chapter on macros and an expanded chapter on crates, two key aspects of Rust that make it so popular. Readers will also find extra appendices on Rust development tools and Rust versions.
AI导读
核心看点
  • Rust官方权威指南,涵盖2018版核心特性
  • 深入讲解所有权机制,保障内存安全与高效
  • 结合Cargo工具链,构建健壮可靠的工程代码
适合谁读
  • 希望系统学习Rust编程语言的初学者
  • 寻求内存安全替代方案的C/C++开发者
  • 对系统级编程及高性能计算感兴趣的程序员
读前提醒
  • 建议优先阅读官网免费在线版,内容同步更新
  • 所有权概念较难,建议配合官方Reference细读
  • 理论结合实践,建议边读边在Exercism练习
读者共识
  • 公认的最佳Rust入门书,社区亲切称为The Book
  • 讲解清晰友好,但知识点零碎需配合文档补充
  • 虽语法复杂有门槛,但掌握后能写出高效代码

本导读基于书籍简介、目录、原文摘录、短评和书评生成,不等同于全文精读。

精彩摘录
  • "定义元组结构体时依然使用struct:关键字开头,并由结构体名称及元组中的类型定义组成。下面的代码中展示了两个分别叫作Color和Point的元组结构体定义:struct Color(i32,i32,i32); struct Point(i32,i32,i32); let black Color(0,0,0); let origin Point(0,0,0);"
  • "隐藏 在第2章的“比较猜测数字与保密数字”一节中,我们曾经看到一个新声明的变量可以覆盖掉旧的同名变量。在Rust世界中,我们把这一现象描述为:第一个变量被等二个变量隐藏(shadow)了。"
  • "在C++中,这种在对象生命周期结束时释放资源的模式有时也被称作资源获取即初始化(Resource Acquisition Is Initialization, RAⅡ)。假如你使用过类似的模式,那么你应该对Rust中的特殊函数drop并不陌生。 这种模式极大地影响了Rust中的许多设计块择,并最终决定了我们现在编写Rust代码的方式。在上面的例子中,这套释放机制看起来也许还算简单,然而一旦把它放置在某些更加复杂的环境中,代码呈现出来的行为往往会出乎你的意料,特别是当我们拥有多个指向同一处堆内存的变量时。让我们接着来看一看其中一些可能的使用场景。"
  • "Rust提供了一系列的功能来帮助我们管理代码,包括决定哪些细节是暴露的、哪些细节是私有的,以及不同的作用域内存在哪些名称。这些功能有时被统称为模块系统(module system),它们包括: 包(package):一个用于构建、测试并分享单元包的Cargol功能。 单元包(crate):一个用于生成库或可执行文件的树形模块结构。 模块(module)及use关键字:它们被用于控制文件结构、作用域及路径的私有性。 路径(pth):一种用于命名条目的方法,这些条目包括结构体、函数和模块等。"
  • "观察Cargo。toml中的内容,你也许会奇怪它居然没有提到src/main.rs,这是因为Cargo会默认将src/mai.rs视作一个二进制单元包的根节点而无须指定,这个二进制单元包与包拥有相同的名称。同样地,假设包的目录中包含文件src/lib.rs,Cargo也会自动将其视作与包同名的库单元包的根节点。Cargo会在构建库和二进制程序时将这些单元包的根节点文件作为参数传递给rustc。"
  • "Tony Hoare,空值的发明者,曾经在2OO9年的一次演讲Null References:TheBillion Dollar Mistake中提到: 这是一个价值数十亿美金的错误设计。当时,我正在为一门面向对象语言中的引用设计一套全面的类型系统。我的目标是,通过编译器自动检查来确保所有关于引用的操作都是百分之百安全的。但是我却没有抵挡住引入一个空引用概念的诱惑,仅仅是因为这样会比较容易去实现这套系统。这导致了无数的错误、漏洞和系统崩溃,并在之后的40多年中造成了价值数10亿美金的损失。 空值的问题在于,当你尝试像使用非空值那样使用空值时,就会触发某种程度上的错误。因为空或非空的属性被广泛散"
  • "Expressions do not include ending semicolons. If you add a semicolon to the end of an expression, you turn it into a statement, and it will then not return a value."
  • "Function bodies are made up of a series of statements optionally ending in an expression."
作者简介
Steve Klabnik is the Community Team Leader for the Rust team at Mozilla, in charge of official Rust community documentation as well as the key Rust community advocate. Klabnik is a frequent speaker at conferences and one of the world's most prolific contributors to Rails projects. Carol Nichols is a member of the Rust Community Team. She's been active in the Rust community and is an organizer of the Rust Belt Rust Conference.
下载
收藏