Installing Rust
Rustup: the Rust installer and version management tool
Windows Subsystem for Linux
Cargo: the Rust build tool and package manager
When you install Rustup you’ll also get the latest stable version of the Rust build tool and package manager, also known as Cargo. Cargo does lots of things:
- build your project with
cargo build
- run your project with
cargo run
- test your project with
cargo test
- build documentation for your project with
cargo doc
- publish a library to crates.io with
cargo publish
To test that you have Rust and Cargo installed, you can run this in your terminal of choice:
cargo --version
Other tools
Rust support is available in many editors:
VS CODE
SUBLIME TEXT 3
ATOM
INTELLIJ IDEA
ECLIPSE
VIM
EMACS
GEANY
Generating a new project
Let’s write a small application with our new Rust development environment. To start, we’ll use Cargo to make a new project for us. In your terminal of choice run:
cargo new hello-rust
This will generate a new directory called hello-rust
with the following files:
hello-rust
|- Cargo.toml
|- src
|- main.rs
-
Cargo.toml
is the manifest file for Rust. It’s where you keep metadata for your project, as well as dependencies.
-
src/main.rs
is where we’ll write our application code.
cargo new
generates a “Hello, world!” project for us!
We can run this program by moving into the new directory that we made and running this in our terminal:cargo run
You should see this in your terminal:
$ cargo run
Compiling hello-rust v0.1.0 (/Users/ag_dubs/rust/hello-rust)
Finished dev [unoptimized + debuginfo] target(s) in 1.34s
Running `target/debug/hello-rust`
Hello, world!
Adding dependencies
A small Rust application
Learn more!
学习资料
Rust语言官网:
https://www.rust-lang.org/learn/get-started
https://www.rust-lang.org/learn
https://doc.rust-lang.org/cargo/
Rust 官方在线工具: https://play.rust-lang.org/
中文官网:https://www.rust-lang.org/zh-CN/
书籍:
The Rust Programming Language:https://doc.rust-lang.org/book
中文版:
Rust程序设计语言:https://kaisery.github.io/trpl-zh-cn/title-page.html
Rust程序设计语言:https://learnku.com/docs/rust-lang/2018
https://zsiciarz.github.io/24daysofrust/index.html
相关教程:
https://www.runoob.com/rust/rust-tutorial.html
https://www.bootwiki.com/rust/rust-module-use-keyword.html