# The Rust Programming Language

## Procesing a Guess

let声明用于创建变量比如

mutable and immutable

In Rust, variables are immutable by default. We’ll be discussing this concept in detail in the (“Variables and Mutability”) section in Chapter 3. The following example shows how to use mut before the variable name to make a variable mutable:

The :: syntax in the ::new line indicates that new is an associated function of the String type. An associated function is implemented on a type, in this case String.

### Handling Potential Failure with the Result Type

Result

## Generating a Secret number

Rust 当前标准库中不具备随机数功能。不过我们可以通过使用外部的 crate。

### Using a Crate to Get More Functionality

Cargo支持 Semantic Versioning(SemVer).

When you build a project for the first time, Cargo figures out all the versions of the dependencies that fit the criteria and then writes them to the Cargo.lock file. When you build your project in the future, Cargo will see that the Cargo.lock file exists and use the versions specified there rather than doing all the work of figuring out versions again. This lets you have a reproducible build automatically. In other words, your project will remain at 0.8.3 until you explicitly upgrade, thanks to the Cargo.lock file.

## Comparing the guess to the Secret Number

### Mismatched Types and Type Inference.

Rust has a strong, static type system. However, it also has type inference. When we wrote let mut guess = String:new(),Rust was able to infer that guess should be a String and didn’t make us write the type.

## Allowing Multiple Guesses with Looping

### Quitting After a Correct Guess

loop 关键字可以创建一个infinite loop，同时添加退出方式。

### Handling Invalid Input

guess 转换的Result进行匹配。

## Summary

At this point, you’ve successfully built the guessing game. Congratulations!

This project was a hands-on way to introduce you to many new Rust concepts: let, match, functions, the use of external crates, and more. In the next few chapters, you’ll learn about these concepts in more detail. Chapter 3 covers concepts that most programming languages have, such as variables, data types, and functions, and shows how to use them in Rust. Chapter 4 explores ownership, a feature that makes Rust different from other languages. Chapter 5 discusses structs and method syntax, and Chapter 6 explains how enums work.