美文网首页
rust 学习 笔记(一)

rust 学习 笔记(一)

作者: 流血的手指 | 来源:发表于2019-02-27 14:22 被阅读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:

    相关文章

      网友评论

          本文标题:rust 学习 笔记(一)

          本文链接:https://www.haomeiwen.com/subject/dpeyyqtx.html