Rust-learn-1

Rust-learn-1

  • Rust-learn-1
    • What is Rust
    • Why I choose Rust
    • Install Rust
      • address
      • verify
    • get learn docs
      • build docs in your local
      • result
    • VSCode for Rust
    • Hello World
      • make a rs file
      • code
      • build exe
      • run exe
    • What is Cargo
      • check Cargo
    • build project by Cargo
      • a usual project
      • check Cargo.toml
    • build exe by Cargo
      • run

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

Rust-learn-1_第1张图片

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
Rust-learn-1_第2张图片

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

Rust-learn-1_第3张图片

run exe

./HelloWorld.exe

Rust-learn-1_第4张图片

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

Rust-learn-1_第5张图片

build project by Cargo

cargo new test_cargo

在这里插入图片描述

a usual project

you will see a project which build by cargo
Rust-learn-1_第6张图片

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
Rust-learn-1_第7张图片

run

./target/debug/test_cargo.exe

在这里插入图片描述

你可能感兴趣的:(Rust,笔记,rust,开发语言,后端)