rust 学习 笔记(一)

2019-02-27  本文已影响1人  流血的手指

1. 打开本地的rust 文档

rustup doc
里面有 install 等 各类详细信息,就不多详述了。

2. cargo

cargo new proj_name
cargo build
cargo build --release  # release 版本
cargo run
cargo check
cargo update  # 升级库的版本,只升级小版本
cargo doc --open   # 查看库(crate)的文档

3. const

const MAX_POINTS: u32 = 100_000;

变量名大写+下划线,下划线可以加到数字中,提高可读性?

shadow & mut

Shadowing is different than marking a variable as mut, because we’ll get a compile-time error if we accidentally try to reassign to this variable without using the let keyword. By using let, we can perform a few transformations on a value but have the variable be immutable after those transformations have been completed.

The other difference between mut and shadowing is that because we’re effectively creating a new variable when we use the let keyword again, we can change the type of the value but reuse the same name. For example, say our program asks a user to show how many spaces they want between some text by inputting space characters, but we really want to store that input as a number:

上一篇 下一篇

猜你喜欢

热点阅读