## File: README.md

<h1 align="center">Rust语言圣经</h1>


   




为国内用户量身打造、最用心的 Rust 教程，新手入门，老手提升生产力。

- 在线阅读: https://course.rs
- 在线练习：https://practice.course.rs
- AI 前沿学习：https://beatai.org 每日精选全球好文，实时、高质、有用



## 创作感悟

Rust 语言圣经已写 170 余章、110 余万字、历经 800 多个小时，每一章节都是纯手工，绝无质量上的妥协( 优秀的读者们应该都有此体会 )。

曾有读者问： 这么好的书为何是开源，而非出版？原因很简单，Rust 要在国内发展起来，必须得有追梦之人去做不计付出的事，我希望自己能贡献一份微薄之力。

但要说完全无欲无求，emmm，看到项目多了一颗 🌟，好像也非常开心，有什么能比读者大大的赞美更宝贵:)

你们用指尖绘制星空，那里繁星点点，每一颗都在激励着我们披荆斩棘、不断前行。不夸张的说，没有你们，开源世界就没有星光，自然也不会有今日的开源盛世。

能与大家在茫茫人海中相识，这感觉真好！






## 🏆 贡献者

非常感谢本教程的[所有贡献者](https://github.com/sunface/rust-course/graphs/contributors)，正是有了你们，才有了现在的高质量 Rust 教程! 特别感谢：



| **EluvK** | **AllanDowney** |
| --- | --- |








| **孙立刚** | **JesseAtSZ** | **Rustln** | **1132719438** |
| --- | --- | --- | --- |




## 开源协议

在开源版权上，我们选择了 [No License](https://choosealicense.com/no-permission/)，这意味着读者可以随意的 fork 和阅读，但是**不能私下修改后再包装分发**，如果有这方面的需求，请联系我们，望理解。

## 借鉴的书籍

站在巨人的肩膀上，能帮我们看的更远，特此感谢以下巨人：

- [Rust Book](https://doc.rust-lang.org/book)
- [Rust nomicon](https://doc.rust-lang.org/nomicon/intro.html)
- [Async Rust](https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html)
- 详细清单参见 [这里](./assets/writing-material/books.md)

因为它们绝大部分是支持 APACHE + MIT 双协议的，因此我们选择了遵循其中的 MIT 协议，并在这里统一对借鉴的书籍进行说明。

---

## File: assets/rustlings-zh/exercises/primitive_types/README.md

# 基本类型（Primitive Types）

Rust 有几个直接在编译器中实现基本类型。在本节中，我们来看看最重要的几个。

## 更多信息

- [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html)
- [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html)

---

## File: assets/rustlings-zh/exercises/option/README.md

# Option

Option 类型代表可选的值：每个 Option 要么是 Some ，包含一个值；要么是 None ，表示空值。
Option 在 Rust 代码中十分常见，因为它有许多用途：
- 初始值
- 输入值不符合定义的情况下作为函数的返回值（部分函数）。
- 返回 None 作为简单错误的返回值
- 可选的结构字段
- 可以借用或 "取走" 的结构字段（的值）
- 可选的函数参数
- 空指针
- 在某些情况下交换值*

译注：“在某些情况下交换值”可以假设有个可变数组，现在要通过两个可变引用来交换其中两个元素的值。但 Rust 显然不允许有两个对数组的可变引用，这时候可以用 Option 包装下元素值，比如：

``` rust
fn main() {
    let mut array = vec![Some(1), Some(2)];
    let a = array.get_mut(0).unwrap().take().unwrap();
    let b = array.get_mut(1).unwrap().replace(a);
    *array.get_mut(0).unwrap() = b;
    println!("{:?}", array);// [Some(2), Some(1)]
}
```

嘿嘿，有点强行了。
[示例参考](https://zulip-archive.rust-lang.org/stream/122651-general/topic/.60Option.60.20.22swapping.20things.20out.20of.20difficult.20situations.22.3F.html)
[关于 Option 的描述来自于](https://doc.rust-lang.org/std/option/)

## 更多信息

- [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions)
- [Option Module Documentation](https://doc.rust-lang.org/std/option/)
- [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html)

---

## File: assets/rustlings-zh/exercises/move_semantics/README.md

# 移动语义（Move Semantics）

这些练习改编自 [pnkfelix](https://github.com/pnkfelix) 的 [Rust Tutorial](https://pnkfelix.github.io/rust-examples-icfp2014/) -- 谢谢 Felix !!!

## 更多信息

以下书籍中的内容对于当前的学习尤其重要。

- [Ownership](https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html)
- [Reference and borrowing](https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html)

---

## File: assets/rustlings-zh/exercises/modules/README.md

# 模块（Modules）

这部分我们将向你介绍 Rust 的模块系统。

## 更多信息

- [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html)

---

## File: assets/rustlings-zh/exercises/macros/README.md

# Macros

Rust's macro system is very powerful, but also kind of difficult to wrap your
head around. We're not going to teach you how to write your own fully-featured
macros. Instead, we'll show you how to use and create them.

## Further information

- [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html)
- [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html)

---

## File: assets/rustlings-zh/exercises/if/README.md

# If

你将在这学习最基本的控制流（control flow）——`if`

## 更多信息

- [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions)

---

## File: assets/rustlings-zh/exercises/generics/README.md

# 泛型

泛型的主旨是把类型和函数泛化到多种情况。
这在很多方面有助于减少重复代码，但也可能需要为此使用相当多的语法。
也就是说，使用泛型的话则需要小心谨慎地标明泛型适用于哪些类型。

## 更多信息

- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html)
- [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html)

---

## File: assets/rustlings-zh/exercises/functions/README.md

# 函数（Functions）

在本练习，你将学习如何编写一个函数，以及 Rust 编译器怎样可以对事物进行追溯（trace things way back）。

译：依据练习的内容，追溯的意思可能是类型推导之类的事。

## 更多信息

- [How Functions Work](https://doc.rust-lang.org/book/ch03-03-how-functions-work.html)

---

## File: assets/rustlings-zh/exercises/error_handling/README.md

# 错误处理
大多数的错误并没有严重到需要让程序完全停止运行的程度。
有时一个函数执行失败时，你可以很容易地对造成失败的原因进行解释并采取对应措施的。
例如，你正试图打开一个文件，但由于该文件不存在导致了操作失败，这时你可能想创建
该文件而不是直接终止程序。

## 更多信息

- [Error Handling](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html)
- [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html)
- [Result](https://doc.rust-lang.org/rust-by-example/error/result.html)
- [Boxing errors](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html)