Rust-learn-1
Rust-learn-1
What is Rust
Rust 语言是一种高效、可靠的通用高级语言。其高效不仅限于开发效率,它的执行效率也是令人称赞的,是一种少有的兼顾开发效率和执行效率的语言。
Rust 语言由 Mozilla 开发,最早发布于 2014 年 9 月。Rust 的编译器是在 MIT License 和 Apache License 2.0 双重协议声明下的免费开源软件。截至目前( 2020 年 1 月)最新的编译器版本是 1.41.0。
Why I choose Rust
actually I am a Java | Vue developer , but gradually I do not settle for make softwares , I wanna make some build tools.And I am satisfied with Rust’s advantages!
Install Rust
Rust docs is very particular,we can install it very easy!if you download correctly, you can even not to configure env variables!
address
https://www.rust-lang.org/zh-CN/tools/install
verify
rustc --version
get learn docs
we can use rustup docs --books
to get the book in your local !
or you can get the translation version from here
build docs in your local
first we should find what we need in GitHub and download zip
then unzip the package
install vuepress
npm i -g vuepress
npm i -g vue-template-compiler
build the src
vuepress build ./src
open the serve
vuepress dev ./src
vuepress may install slowly , so you should have so patience 😎
result
VSCode for Rust
we use VSCode as our ‘IDEA’ ,and we need to download these extenions
Hello World
make a rs file
I make a HelloWorld.rs
code
fn:function
main():like java,c,c++…,the main function,which is the enter of the programe,and it always run first!
println!:focus ! it mean that is a rust macro
fn main(){
println!("hello world!")
}
build exe
rustc ./HelloWorld.rs
run exe
./HelloWorld.exe
What is Cargo
Cargo is Rust’s build system and package manager. Most Rustaceans use Cargo to manage their Rust projects because it can handle many tasks for you, such as building code, downloading dependency libraries, and compiling these libraries
check Cargo
cargo --version
build project by Cargo
cargo new test_cargo
a usual project
you will see a project which build by cargo
check Cargo.toml
[package]
name = "test_cargo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
build exe by Cargo
cargo build
after compiler you can find a target package
run
./target/debug/test_cargo.exe