美文网首页rust
rust学习总结-1

rust学习总结-1

作者: robertzhai | 来源:发表于2022-02-20 15:55 被阅读0次

安装

install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup -V
rustup component add rust-src
rustc -V

rustc 1.58.1 (db9d1b20b 2022-01-20

cargo -V

cargo 1.58.0 (f01b232bc 2022-01-19)

卸载

rustup self uninstall

ide

IntelliJ IDEA
https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-quick-start.html

new project

cargo new start && cd start
.
├── Cargo.lock
├── Cargo.toml
├── src
│   └── main.rs
└── target
    ├── CACHEDIR.TAG
    └── debug
        ├── build
        ├── deps
        ├── examples
        ├── incremental
        ├── start
        └── start.d

本地文档

rustup doc

Rust 项目类型

主要分为两个类型:bin 和 lib,前者是一个可运行的项目,后者是一个依赖库项目。

编译项目 (debug +release模式)

cargo build
cargo build --release

运行项目

./target/debug/start
cargo run
cargo run --release
./target/release/start

更快的方式来验证代码的正确性

cargo check

Cargo.toml 和 Cargo.lock

Cargo.toml 是 cargo 特有的项目数据描述文件。它存储了项目的所有元配置信息,如果 Rust 开发者希望 Rust 项目能够按照期望的方式进行构建、测试和运行,那么,必须按照合理的方式构建 Cargo.toml。
Cargo.lock 文件是 cargo 工具根据同一项目的 toml 文件生成的项目依赖详细清单,因此我们一般不用修改它,只需要对着 Cargo.toml 文件撸就行了。
什么情况下该把 Cargo.lock 上传到 git 仓库里?很简单,当你的项目是一个可运行的程序时,就上传 Cargo.lock,如果是一个依赖库项目,那么请把它添加到 .gitignore 中

参考

相关文章

  • rust学习总结-1

    安装 install[https://www.rust-lang.org/zh-CN/tools/install]...

  • rust基础学习总结

    1,对象实现Clone等接口 impl Clone for Obj { fn clone(&self)->Se...

  • rust学习总结-3

    _占位符 忽略该值或者类型,类似go中的 使用下划线开头忽略未使用的变量, 不会产生警告 _x 仍会将值绑定到变量...

  • rust学习总结-4

    Vector 动态数组类型用Vec 访问元素,确保索引不会越界的时候,就用索引访问,否则用 .get(索引超...

  • rust学习总结-2

    声明变量 let 可变性 默认不可变mut 修饰可变 变量遮蔽(shadowing) Rust 允许声明相同的变量...

  • rust学习总结001

  • rust学习总结002

    rust 哈希表常用操作 获取 HashMap 成员 hashMap[key]hashMap.get(key)

  • Rust学习笔记(1)

    内容整理自:https://doc.rust-lang.org/book/title-page.html Chap...

  • rust学习1——安装

    安装 直接进官网,mac上: 由于我用的是fish,不支持~/.cargo/env里的case语法,所以我们需要把...

  • 二零一七年二月

    技术 Rust 中文WikiRust PlaygroundRust学习资源和路线Rust in Detail: W...

网友评论

    本文标题:rust学习总结-1

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