├── io_file ├── content.txt ├── Cargo.toml └── src │ └── main.rs ├── testing ├── src │ └── main.rs └── Cargo.toml ├── hello ├── main ├── main.rs └── 2021-01-10.md ├── hello_cargo ├── src │ └── main.rs ├── Cargo.lock ├── Cargo.toml └── 2021-01-13.md ├── variable ├── variable └── variable.rs ├── scalar_type ├── scalar_type ├── tempCodeRunnerFile └── scalar_type.rs ├── enums ├── Cargo.toml └── src │ └── main.rs ├── as_parse ├── Cargo.toml └── src │ └── main.rs ├── hashmap ├── Cargo.toml └── src │ └── main.rs ├── scope_type ├── Cargo.toml └── src │ └── main.rs ├── higher_func ├── Cargo.toml └── src │ └── main.rs ├── trait_system ├── Cargo.toml └── src │ └── main.rs ├── array ├── Cargo.toml └── src │ └── main.rs ├── slice ├── Cargo.toml └── src │ └── main.rs ├── struct ├── Cargo.toml └── src │ └── main.rs ├── tuple ├── Cargo.toml └── src │ └── main.rs ├── condition ├── Cargo.toml └── src │ └── main.rs ├── function ├── Cargo.toml └── src │ └── main.rs ├── operator ├── Cargo.toml └── src │ └── main.rs ├── string_type ├── Cargo.toml └── src │ └── main.rs ├── loop_for_while ├── Cargo.toml └── src │ └── main.rs ├── README.md ├── LICENSE └── .gitignore /io_file/content.txt: -------------------------------------------------------------------------------- 1 | this is file content. -------------------------------------------------------------------------------- /testing/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("width!"); 3 | } 4 | -------------------------------------------------------------------------------- /hello/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auula/learning-rust-zh/HEAD/hello/main -------------------------------------------------------------------------------- /hello/main.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | // 既然是中文教程我搞点中文 3 | println!("您好,rust!") 4 | } -------------------------------------------------------------------------------- /hello_cargo/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /variable/variable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auula/learning-rust-zh/HEAD/variable/variable -------------------------------------------------------------------------------- /scalar_type/scalar_type: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auula/learning-rust-zh/HEAD/scalar_type/scalar_type -------------------------------------------------------------------------------- /scalar_type/tempCodeRunnerFile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auula/learning-rust-zh/HEAD/scalar_type/tempCodeRunnerFile -------------------------------------------------------------------------------- /hello_cargo/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "hello_cargo" 5 | version = "0.1.0" 6 | -------------------------------------------------------------------------------- /enums/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "enums" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /as_parse/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "as_parse" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /hashmap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hashmap" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /io_file/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "io_file" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /testing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "testing" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /scope_type/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "scope_type" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /higher_func/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "higher_func" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /trait_system/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "trait_system" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /array/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "array" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /slice/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "slice" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /struct/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "demo" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /tuple/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tuple" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /condition/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "condition" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /function/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "funcation" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /operator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "operator" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /string_type/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "string_type" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /loop_for_while/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "loop_for_while" 3 | version = "0.1.0" 4 | authors = ["Dings "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /as_parse/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x: i32 = 960; 3 | println!("{:?}", x); 4 | let x: i64 = x as i64; 5 | println!("{}", x); 6 | let x: char = '丁'; 7 | println!("{}", x); 8 | let x: u8 = x as u8; 9 | println!("{}", x); 10 | let strs = "21".to_string(); 11 | let num = strs.parse::().unwrap(); 12 | println!("num = {}", num) 13 | } 14 | -------------------------------------------------------------------------------- /hello_cargo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | # 项目名字 3 | name = "hello_cargo" 4 | # 项目版本 5 | version = "0.1.0" 6 | # 开发者信息 7 | authors = ["Dings "] 8 | # edition 字段表明代码应该使用哪个版本编译。如果该字段不存在,其默认为 2015 以提供后向兼容性 9 | edition = "2018" 10 | 11 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 | 13 | # 项目依赖的相关配置 14 | [dependencies] 15 | -------------------------------------------------------------------------------- /higher_func/src/main.rs: -------------------------------------------------------------------------------- 1 | type MathOp = fn(i32, i32); 2 | 3 | fn add(x: i32, y: i32) { 4 | println!("{} - {} = {}", x, y, x + y) 5 | } 6 | 7 | fn sub(x: i32, y: i32) { 8 | println!("{} - {} = {}", x, y, x - y) 9 | } 10 | 11 | fn MathFunc(op: MathOp, tup: (i32, i32)) { 12 | op(tup.0, tup.1); 13 | } 14 | 15 | fn main() { 16 | // 高阶函数 17 | MathFunc(add, (100, 200)) 18 | } 19 | -------------------------------------------------------------------------------- /enums/src/main.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | enum Colors { 3 | Red, 4 | Blue, 5 | Yellow, 6 | Green, 7 | } 8 | 9 | fn main() { 10 | let param = Colors::Blue; 11 | match param { 12 | Colors::Red => println!("红色"), 13 | Colors::Blue => println!("蓝色"), 14 | Colors::Yellow => println!("黄色"), 15 | Colors::Green => println!("绿色"), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /slice/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let key: &'static str = "sync_lock"; 3 | if up_lock(key, 1) == 1 { 4 | // 设置超时 5 | expire(key, 30) 6 | // .....业务逻辑 7 | } 8 | } 9 | 10 | // 基于redis SETNX 和 EXPIRE 的实现,问题代码 11 | fn up_lock(key: &'static str, num: i8) -> i8 { 12 | // ..... 上锁逻辑 13 | return 1; 14 | } 15 | 16 | fn expire(key: &'static str, num: i8) { 17 | // ... 自定义超时 18 | } 19 | -------------------------------------------------------------------------------- /scope_type/src/main.rs: -------------------------------------------------------------------------------- 1 | // 在rust中通常一在一个数到另外一个数的整数序列中的所有数字我们叫范围类型 2 | fn main() { 3 | print!("(1..5)="); 4 | for i in 1..5 { 5 | print!("{}", i); 6 | } 7 | println!(); 8 | print!("(1..=5)"); 9 | for i in 1..=5 { 10 | print!("{}", i); 11 | } 12 | println!(); 13 | // 1-5累加求和 14 | let sum: i64 = (1..=5).sum(); 15 | println!("sum = {}", sum); 16 | // 生成1-5的数 然后反转 17 | let rev = (1..=5).rev(); 18 | for i in rev { 19 | print!("{}", i) 20 | } 21 | println!(); 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔝通知: 项目文档迁移到: https://github.com/higker/learn-rust 2 | 3 | ## learning-rust-zh 4 | 个人的 rust 学习资料 5 | 6 | 7 | 8 | ## 学习目录 9 | 10 | |目录|源代码地址|相关解析| 11 | |---|---|-------| 12 | |第一个rust程序|https://github.com/higker/learning-rust-zh/tree/main/hello|https://t.1yb.co/ewqd| 13 | |了解工具链|https://github.com/higker/learning-rust-zh/tree/main/hello_cargo |https://t.1yb.co/eVxb| 14 | |Rust中的变量|https://github.com/higker/learning-rust-zh/tree/main/variable|https://t.1yb.co/fPIu| 15 | |Rust中的类型|https://github.com/higker/learning-rust-zh/tree/main/scalar_type|https://t.1yb.co/g39W| 16 | -------------------------------------------------------------------------------- /io_file/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::fs::File; 2 | use std::io::Read; 3 | 4 | fn main() { 5 | println!( 6 | "{}", 7 | read_file_content("/Users/ding/Desktop/learning-rust-zh/io_file/content.txt") 8 | ) 9 | } 10 | 11 | fn read_file_content(path: &str) -> String { 12 | let mut f = match File::open(path) { 13 | Ok(f) => f, 14 | Err(error) => { 15 | panic!("problem openting the file {:?}", error) 16 | } 17 | }; 18 | let mut contents = String::new(); 19 | match f.read_to_string(&mut contents) { 20 | Ok(_) => contents, 21 | Err(e) => { 22 | panic!("problem read file content {:?} ", e) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /function/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | say_hi(); 3 | assert_eq!(assert_sum(),sum()); 4 | let name = "Jarvib"; 5 | edit_name(name); 6 | println!("main() Your name is {}",name); 7 | 8 | let mut no:i32 = 22; 9 | println!("The value of no is:{}",no); 10 | mutate_no_to_zero(&mut no); 11 | println!("The value of no is:{}",no); 12 | } 13 | 14 | fn say_hi() { 15 | println!("👋 Hello!"); 16 | } 17 | 18 | 19 | fn sum() -> i8 { 20 | return 5 + 5; 21 | } 22 | 23 | fn assert_sum() -> i8 { 24 | 5 + 5 25 | } 26 | 27 | fn edit_name(mut name:&'static str){ 28 | name = "Jarvib Ding"; 29 | println!("edit_name() Your name is {}",name) 30 | } 31 | 32 | fn mutate_no_to_zero(param_no:&mut i32){ 33 | *param_no = 0; //解引用操作 34 | } -------------------------------------------------------------------------------- /condition/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let age = 22; 3 | if age > 18 { 4 | println!("你已经成年了!") 5 | } else { 6 | println!("未成年人!") 7 | } 8 | 9 | let num = 2; 10 | if num > 0 { 11 | println!("{} is positive", num); 12 | } else if num < 0 { 13 | println!("{} is negative", num); 14 | } else { 15 | println!("{} is neither positive nor negative", num); 16 | } 17 | 18 | //match 语句有返回值,它把 匹配值 后执行的最后一条语句的结果当作返回值 19 | 20 | let month = "二月"; 21 | 22 | let english_month = match month { 23 | "一月" => "January", 24 | "二月" => "February", 25 | "三月" => "March", 26 | "四月" => "April", 27 | _ => "Unknown", 28 | }; 29 | println!("{}", english_month) 30 | } 31 | -------------------------------------------------------------------------------- /loop_for_while/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut sum: u16 = 0; 3 | for i in 1..100 { 4 | sum += i; 5 | } 6 | println!("sum = {}", sum); 7 | 8 | sum = 0; 9 | while sum < 100 { 10 | sum += 1; 11 | } 12 | println!("sum = {}", sum); 13 | 14 | let mut n = 0; 15 | loop { 16 | if n == 100 { 17 | // stop action 18 | break; 19 | } 20 | n += 1; 21 | } 22 | println!("n = {}", n); 23 | 24 | n = 0; 25 | loop { 26 | n += 1; 27 | if n == 100 { 28 | // stop action 29 | break; 30 | } 31 | if n % 2 == 0 { 32 | // stop action 33 | println!("偶数 {}", n); 34 | continue; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /struct/src/main.rs: -------------------------------------------------------------------------------- 1 | struct UserInfo { 2 | name: String, 3 | age: u8, 4 | is_man: bool, 5 | weight: f32, 6 | } 7 | 8 | impl UserInfo { 9 | fn gender(&self) -> &'static str { 10 | if self.is_man { 11 | return "is a boy. "; 12 | } 13 | "is a girl." 14 | } 15 | fn say_hi(&self) { 16 | println!( 17 | "Hi, my name is {},age is {} and weight is {} kg,{}", 18 | self.name, 19 | self.age, 20 | self.weight, 21 | self.gender() 22 | ); 23 | } 24 | } 25 | 26 | fn main() { 27 | let user = UserInfo { 28 | name: String::from("Jarvib Ding"), 29 | age: 0x16, 30 | is_man: true, 31 | weight: 67.8, 32 | }; 33 | // Hi, my name is Jarvib Ding,age is 22 and weight is 67.8 kg,is a boy. 34 | user.say_hi() 35 | } 36 | -------------------------------------------------------------------------------- /tuple/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let tuples: (&'static str, i8, f64) = ("🦀", 22, 3.1415927); 3 | println!("{:?}", tuples); 4 | // 声明一个可变的tuple 5 | let mut people = ("tom", "robin", "jarvib"); 6 | // 通过下标访问 7 | println!("{},{},{}", people.0, people.1, people.2); 8 | // 修改下标为2的值 9 | people.2 = "Jarvib Ding"; 10 | let (v1, v2, v3) = people; 11 | println!("{},{},{}", v1, v2, v3); 12 | 13 | // 二维的元组 14 | let tuples_2d = (1024, ("Rust", '🦀')); 15 | 16 | println!("tuples_2d.1.1 = {}", tuples_2d.1 .1); 17 | 18 | // 指定数据类型 19 | let tup_type: (i8, i32, bool) = (21, -1024, true); 20 | // 解构元素 21 | let (one, two, three) = tup_type; 22 | // 二维的元组 23 | let tup_2d: (f64, (i8, i32, bool)) = (3.1415927, (one, two, three)); 24 | println!("tup_2d = {:?}", tup_2d); 25 | // 索引 26 | println!("π = {:?}", tup_2d.0); 27 | } 28 | -------------------------------------------------------------------------------- /scalar_type/scalar_type.rs: -------------------------------------------------------------------------------- 1 | // Rust 标量数据类型 2 | // 标量数类型: 只有一个值,复合类型是通过标量类型构成的 3 | 4 | // 1. 整数类型 5 | // 2. 浮点类型 6 | // 3. 布尔类型 7 | // 4. 字符类型 8 | fn main(){ 9 | // 整型 10 | let i = 00_32; // default scalar type i32 11 | let age:u8 = 0x16; 12 | let num:i64 = -00_64; 13 | let iarch:isize = i; 14 | let uarch:usize = 64; 15 | println!("i = {} age = {} num = {}",i,age,num); 16 | println!("iarch = {} uarch = {}",iarch,uarch); 17 | 18 | // 浮点型 19 | let f = 64.00; 20 | println!("f is {:?}",f); 21 | // let f:i64 = f; 22 | // println!("f is {:?}",f) 23 | 24 | // 布尔类型 25 | let b = true; 26 | println!("b = {:?}",b); 27 | 28 | // 字符 29 | let special_character = '@'; //default 30 | let alphabet:char = 'A'; 31 | let chinese:char = '丁'; 32 | let emoji:char = '😜'; // 笑脸的那个图 33 | 34 | println!("special character is {}",special_character); 35 | println!("alphabet is {}",alphabet); 36 | println!("chinese is {:?}",chinese); 37 | println!("emoji is {}",emoji); 38 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jarvib Ding 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /variable/variable.rs: -------------------------------------------------------------------------------- 1 | // Rust中的变量 2 | // Author: SDing 3 | 4 | // 1. 不可变变量 5 | // 2. 可变变量 6 | // 3. 变量的重影 7 | 8 | fn main(){ 9 | // 通过let 声明的变量是不可变的 10 | let v = "variable"; 11 | println!("这是一个不可变的变量: {}",v); 12 | // unexpected token 13 | //v = "var 2" 14 | //println!("{}",v) 15 | let v = "new ".to_owned() + v; 16 | println!("重影: {}",v); 17 | 18 | // 通过mut关键字声明的变量可以被修改 19 | let mut m = 123; 20 | //println!("m assigned value is {}",m); 21 | m = 666 + m; 22 | println!("这是一个可变变量: {}",m); 23 | 24 | // 重影 Shadowing 25 | let s = 32; 26 | let s = 32 + s; 27 | println!("s value is {}",s); 28 | let s = s - 32; 29 | println!("s value assigned value is {}",s); 30 | // 运行代码编译器没有报错,很多人就奇怪了,let声明的变量不是不可变吗? 31 | // 对的,let关键字重新声明的相同变量的名的变量会砍掉之前的变量 32 | // 并且如果需要之前变量的值就会拿到值然后在删除掉,重新分配 33 | 34 | // 可以通过查看内存地址就查看 35 | println!("old s pointer is {:p}",&s); 36 | let s = s; 37 | println!("new s pointer is {:p}",&s); 38 | 39 | // 补充常量 40 | // 定义常量时必须指定数据类型,而定义变量时数据类型可以省略 41 | const MY_AGE:u64 = 21; 42 | println!("my age is {}",MY_AGE) 43 | } -------------------------------------------------------------------------------- /hashmap/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | fn main() { 4 | //通过泛型创建一个map 5 | let mut map: HashMap<&str, i32> = HashMap::new(); 6 | 7 | map.insert("Java", 100); 8 | map.insert("Golang", 80); 9 | map.insert("Rust", 70); 10 | 11 | println!("{:?}", map); 12 | 13 | // 交换Java和Rust 14 | if let Some(ele) = map.insert("Java", 90) { 15 | map.insert("Rust", ele); 16 | } 17 | println!("{:#?}", map); 18 | // key有值的话不做操作,反之插入值 19 | map.entry("JavaScript").or_insert(86); 20 | 21 | //遍历map 22 | for (i, v) in map.iter_mut() { 23 | println!("index = {} value = {}", i, v); 24 | } 25 | //println!("Hello {0:1$}", 5, "x"); 26 | 27 | // 移除指定的key 28 | if map.contains_key("Java") { 29 | map.remove("Java"); 30 | } 31 | println!("{:#?}", map); 32 | 33 | let key: String = String::from("key"); 34 | 35 | let mut value: String = String::from("value"); 36 | 37 | let mut map_string: HashMap<&String, &String> = HashMap::new(); 38 | 39 | // 引用和借用 40 | map_string.insert(&key, &mut value); 41 | 42 | //value.clear(); 43 | 44 | println!("value = {:?}", map_string.get(&key)) 45 | } 46 | -------------------------------------------------------------------------------- /array/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut year: [i32; 4] = [1999, 2019, 2020, 2021]; 3 | // let arr = [10,20,30,40]; 4 | println!("array is {:?}", year); 5 | // len() 数组长度 6 | println!("array size is :{}", year.len()); 7 | 8 | for index in 0..year.len() { 9 | println!("index: {} , value: {}", index, year[index]); 10 | } 11 | 12 | for value in year.iter() { 13 | println!("value is: {}", value); 14 | } 15 | 16 | updated_by_index(2, 2021, &mut year); 17 | println!("updated of {:?}", year); 18 | 19 | delete_by_index(1, &mut year) 20 | } 21 | 22 | // 通过下标修改某个元素的值 23 | fn updated_by_index(index: usize, value: i32, arr: &mut [i32; 4]) { 24 | arr[index] = value; 25 | } 26 | 27 | // 通过下标删除某个元素 28 | fn delete_by_index(index: usize, arr: &mut [i32; 4]) { 29 | // 新数组,长度为原始数组减去 1 30 | let mut new: [i32; 3] = [-1; 3]; 31 | for i in 0..new.len() { 32 | if index <= 0 || index >= arr.len() { 33 | println!("下标越界!") 34 | } 35 | if i < index { 36 | new[i] = arr[i]; 37 | } else { 38 | new[i] = arr[i + 1] 39 | } 40 | } 41 | // return new; 42 | println!("new arr {:?}", new) 43 | } 44 | -------------------------------------------------------------------------------- /string_type/src/main.rs: -------------------------------------------------------------------------------- 1 | // Rust中的字符串 2 | 3 | // 1. Rust中的字符串面量 4 | // 2. String标准库 5 | 6 | const SHANG_HAI: &str = "上海"; 7 | 8 | fn main() { 9 | // 常量只能 被赋值为 常量表达式/数学表达式,不能是 函数返回值 或者其它只有在运行时才能确定的值。 10 | println!("SHANG_HAI = {}", SHANG_HAI); 11 | 12 | // 字符串字面量模式是 静态的 这就意味着字符串字面量从创建时开始会一直保存到程序结束 13 | let city = "上海"; 14 | let programmer = "rust coder"; 15 | println!("city {0} programmer = {1}", city, programmer); 16 | // 字符串面量默认就是“静态”的 你可以通过static关键字显示声明 17 | let name: &'static str = "Jarvib Ding"; 18 | println!("my name is {name}", name = name); 19 | 20 | // 字符串对象 21 | let mut phone = String::new(); 22 | phone.push_str("Apple iPhone 11"); 23 | let iphone = String::from(phone); 24 | println!("{}", iphone); 25 | 26 | // 1 {{Hello}} 27 | let mut hello_string = String::new(); 28 | hello_string.push_str("{"); 29 | hello_string.push_str("Hello"); 30 | hello_string.push_str("}"); 31 | println!("{}", hello_string); 32 | // 2 {{Hello}} 33 | println!("{left}Hello{right}", left = "{", right = "}"); 34 | // 3 {{Hello}} 35 | println!("{{{}}}", "hello"); 36 | 37 | let hello = String::from("Hello, world!"); 38 | 39 | println!("{}", hello); 40 | 41 | let url = "https://getrust.tech"; 42 | let mut domain = url.to_string(); 43 | domain = domain.replace("https://", ""); 44 | println!("domain is {}", domain); 45 | } 46 | -------------------------------------------------------------------------------- /operator/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // 加减乘除 3 | let result = 11 + 11; 4 | println!("11 + 11 = {}", result); 5 | println!("11 - 11 = {}", 11 - 11); 6 | println!("11 * 11 = {}", 11 * 11); 7 | println!("11 / 11 = {}", 11 / 11); 8 | println!("11 % 11 = {}", 11 % 11); 9 | 10 | // 关系运算 11 | println!("1 > 0 {}", 1 > 0); 12 | println!("0 < 1 {}", 0 < 1); 13 | println!("21 >= 21 {}", 21 >= 21); 14 | println!("21 <= 21 {}", 21 <= 21); 15 | println!("0 == 0 {}", 0 == 0); 16 | println!("0 != 0 {}", 0 != 0); 17 | 18 | // 逻辑与 逻辑或 逻辑非 (取反) 19 | println!("1 == 1 && 0 != 1 {}", 1 == 1 && 0 != 1); 20 | println!("1 == 1 || 0 != 1 {}", 1 == 1 || 0 != 1); 21 | println!("!(1 == 1) {}", !(1 == 1)); 22 | 23 | let a = 20; 24 | let b = 30; 25 | 26 | if (a > 10) && (b > 10) { 27 | println!("true"); 28 | } 29 | let c = 0; 30 | let d = 30; 31 | 32 | if (c > 10) || (d > 10) { 33 | println!("true"); 34 | } 35 | let is_elder = false; 36 | 37 | if !is_elder { 38 | println!("Not Elder"); 39 | } 40 | 41 | // 位运算符 42 | 43 | let a: i32 = 2; // 二进制表示为 0 0 0 0 0 0 1 0 44 | let b: i32 = 3; // 二进制表示为 0 0 0 0 0 0 1 1 45 | 46 | let mut result: i32; 47 | 48 | result = a & b; 49 | println!("(a & b) => {} ", result); 50 | 51 | result = a | b; 52 | println!("(a | b) => {} ", result); 53 | 54 | result = a ^ b; 55 | println!("(a ^ b) => {} ", result); 56 | 57 | result = !b; 58 | println!("(!b) => {} ", result); 59 | 60 | result = a << b; 61 | println!("(a << b) => {}", result); 62 | 63 | result = a >> b; 64 | println!("(a >> b) => {}", result); 65 | } 66 | -------------------------------------------------------------------------------- /hello/2021-01-10.md: -------------------------------------------------------------------------------- 1 | 2 | ![Rust吉祥物](https://tva1.sinaimg.cn/large/008eGmZEgy1gmj018vmi6j30og0gbjsd.jpg) 3 | 4 | ## 前 言 5 | 6 | > 由于个人原因决定再学习一门语言,那这个语言就是`rust`的了,另外我还把我学习笔记通过`github`开源的方式进行整理开源,那今天我们就从rust环境搭建到第一个程序开始。 7 | 8 | ## rust介绍 9 | 10 | > [Rust](https://www.rust-lang.org/ "Rust") 是一门系统级编程语言,被设计为保证内存和线程安全,防止段错误产生。作为系统级编程语言,它的基本理念是“零开销抽象”。理论上来说,它的速度与 C/C++ 同级。Rust 可以被归为通用的、多范式、编译型的编程语言,类似 C/C++。与这两门编程语言不同的是,Rust 是线程安全的!Rust 编程语言的目标是,创建一个安全和并发的软件系统。它强调安全性、并发和内存控制。尽管 Rust 借用了 C/C++ 的语法,却杜绝了空指针和悬挂指针,而这二者是 C/C++ 中系统崩溃、内存泄露和不安全代码的根源。 11 | 12 | 那我为什么要学习`rust`,这个问题我觉得官方网站就有答案😜。 13 | 14 | ## 对比其他语言 15 | 16 | 这里我们比较的是相关语言在处理一些函数的速度,数据来源`debian`的[benchmarksgame](https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust.html "benchmarksgame"),如下图: 17 | 18 | ![rust对比c](https://tva1.sinaimg.cn/large/008eGmZEgy1gmiz2z37j7j30ti0sen0l.jpg) 19 | 20 | 速度几乎和C差不多,使用其他语言就不要看了,我怕伤人啊。 21 | 22 | 23 | ## 环境搭建 24 | 25 | 这里我本人使用的MacOS进行开发所有我只能演示在Mac上进行配置过程。 26 | 27 | 1. 在你的terminal输入下面命令 28 | 29 | ```bash 30 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 31 | ``` 32 | ![过程](https://tva1.sinaimg.cn/large/008eGmZEgy1gmiza3n2j5j30rz0lttcf.jpg) 33 | 34 | 过程可能有点慢,这个可能有网络原因。 35 | 36 | 2. 验证是否安装成功&查询版本`rustc --version` 37 | 38 | ![相关提示](https://tva1.sinaimg.cn/large/008eGmZEgy1gmizdbvzu9j30au037jrs.jpg) 39 | 40 | 如果有回显,说明你安装成功,欢迎来到🦀螃蟹窝~ 41 | 42 | ## 开始第一个程序 43 | 44 | 既然安装好了Rust,我们来编写第一个 Rust 程序。当学习一门新语言的时候,使用该语言在屏幕上打印 Hello, world! 是一项传统,我们将沿用这一传统! 45 | 46 | 1. 创建项目 47 | 48 | ![项目创建](https://tva1.sinaimg.cn/large/008eGmZEgy1gmizjtmtypj30p00b4421.jpg) 49 | 50 | 2. 创建`main.rs`文件写入 51 | 52 | ```rust 53 | fn main(){ 54 | // 既然是中文教程我搞点中文 55 | println!("您好,rust!") 56 | } 57 | ``` 58 | 3. 然后编译和运行 59 | 60 | ```bash 61 | rustc main.rs 62 | ./main 63 | ``` 64 | ![编译&运行](https://tva1.sinaimg.cn/large/008eGmZEgy1gmizpkw4wlj30pa0c9408.jpg) 65 | 66 | **到此你第一个rust程序写完了,Good luck~** 67 | 68 | ## 关键字列表 69 | 70 | ![rust关键字](https://tva1.sinaimg.cn/large/008eGmZEgy1gmizvg7vhfj30oi1f744j.jpg) 71 | 72 | ## 保留关键字 73 | 74 | ![rust保留关键字](https://tva1.sinaimg.cn/large/008eGmZEgy1gmizwew6rej30oh03k0ss.jpg) 75 | 76 | ## 代码仓库 77 | - https://github.com/higker/learning-rust-zh 78 | - 给个star呗! -------------------------------------------------------------------------------- /trait_system/src/main.rs: -------------------------------------------------------------------------------- 1 | // 矩形 泛型 2 | #[derive(Debug)] 3 | struct Rectangle { 4 | width: T, 5 | height: T, 6 | } 7 | 8 | // 实现泛型trait 9 | impl Rectangle { 10 | pub fn width(&self) -> &T { 11 | &self.width 12 | } 13 | pub fn height(&self) -> &T { 14 | &self.height 15 | } 16 | } 17 | 18 | // 接口特性 19 | trait Geometry { 20 | fn area(&self) -> i32; 21 | } 22 | 23 | // 为i32类型的实现求面积特性 24 | impl Geometry for Rectangle { 25 | fn area(&self) -> i32 { 26 | self.width * self.height 27 | } 28 | } 29 | 30 | // 为rectangle实现i32方法 31 | impl Rectangle { 32 | pub fn area(&self) -> f32 { 33 | self.width * self.height 34 | } 35 | } 36 | 37 | fn option_add(x: Option, y: Option) -> Option { 38 | return if x.is_none() && y.is_none() { 39 | None 40 | } else if x.is_none() { 41 | y 42 | } else if y.is_none() { 43 | x 44 | } else { 45 | Some(y.unwrap() + x.unwrap()) 46 | }; 47 | } 48 | 49 | struct Computer { 50 | brand: String, 51 | } 52 | 53 | trait USB2 { 54 | fn usb_2(&self); 55 | } 56 | 57 | trait USB3 { 58 | fn usb_3(&self); 59 | } 60 | 61 | impl USB2 for Computer { 62 | fn usb_2(&self) { 63 | println!("{} impl usb2.0 ", &self.brand) 64 | } 65 | } 66 | 67 | impl USB3 for Computer { 68 | fn usb_3(&self) { 69 | println!("{} impl usb3.0 ", &self.brand) 70 | } 71 | } 72 | 73 | // usb(pc:impl USB3+USB2) 74 | fn usb(pc: T) 75 | where 76 | T: USB3 + USB2, 77 | { 78 | pc.usb_2(); 79 | pc.usb_3(); 80 | } 81 | 82 | fn main() { 83 | let rtl = Rectangle { 84 | width: 6, 85 | height: 12, 86 | }; 87 | 88 | // method `area` not found for this 89 | println!("area = {}", rtl.area()); 90 | println!("width = {}", rtl.width()); 91 | println!("height = {}", rtl.height()); 92 | println!("{:?}", rtl); 93 | 94 | let area_func = |g: &dyn Geometry| println!("area_func = {}", g.area()); 95 | 96 | area_func(&rtl); 97 | 98 | println!("option_add = {:?}", option_add(Some(1f32), Some(9f32))); 99 | 100 | usb(Computer { 101 | brand: "Dell".to_string(), 102 | }) 103 | } 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig 2 | 3 | # Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,jetbrains,rust,vscode 4 | # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,jetbrains,rust,vscode 5 | 6 | ### JetBrains ### 7 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 8 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 9 | 10 | # User-specific stuff 11 | .idea/**/workspace.xml 12 | .idea/**/tasks.xml 13 | .idea/**/usage.statistics.xml 14 | .idea/**/dictionaries 15 | .idea/**/shelf 16 | 17 | # Generated files 18 | .idea/**/contentModel.xml 19 | 20 | # Sensitive or high-churn files 21 | .idea/**/dataSources/ 22 | .idea/**/dataSources.ids 23 | .idea/**/dataSources.local.xml 24 | .idea/**/sqlDataSources.xml 25 | .idea/**/dynamic.xml 26 | .idea/**/uiDesigner.xml 27 | .idea/**/dbnavigator.xml 28 | 29 | # Gradle 30 | .idea/**/gradle.xml 31 | .idea/**/libraries 32 | 33 | # Gradle and Maven with auto-import 34 | # When using Gradle or Maven with auto-import, you should exclude module files, 35 | # since they will be recreated, and may cause churn. Uncomment if using 36 | # auto-import. 37 | # .idea/artifacts 38 | # .idea/compiler.xml 39 | # .idea/jarRepositories.xml 40 | # .idea/modules.xml 41 | # .idea/*.iml 42 | # .idea/modules 43 | # *.iml 44 | # *.ipr 45 | 46 | # CMake 47 | cmake-build-*/ 48 | 49 | # Mongo Explorer plugin 50 | .idea/**/mongoSettings.xml 51 | 52 | # File-based project format 53 | *.iws 54 | 55 | # IntelliJ 56 | out/ 57 | 58 | # mpeltonen/sbt-idea plugin 59 | .idea_modules/ 60 | 61 | # JIRA plugin 62 | atlassian-ide-plugin.xml 63 | 64 | # Cursive Clojure plugin 65 | .idea/replstate.xml 66 | 67 | # Crashlytics plugin (for Android Studio and IntelliJ) 68 | com_crashlytics_export_strings.xml 69 | crashlytics.properties 70 | crashlytics-build.properties 71 | fabric.properties 72 | 73 | # Editor-based Rest Client 74 | .idea/httpRequests 75 | 76 | # Android studio 3.1+ serialized cache file 77 | .idea/caches/build_file_checksums.ser 78 | 79 | ### JetBrains Patch ### 80 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 81 | 82 | # *.iml 83 | # modules.xml 84 | # .idea/misc.xml 85 | # *.ipr 86 | 87 | # Sonarlint plugin 88 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 89 | .idea/**/sonarlint/ 90 | 91 | # SonarQube Plugin 92 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 93 | .idea/**/sonarIssues.xml 94 | 95 | # Markdown Navigator plugin 96 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 97 | .idea/**/markdown-navigator.xml 98 | .idea/**/markdown-navigator-enh.xml 99 | .idea/**/markdown-navigator/ 100 | 101 | # Cache file creation bug 102 | # See https://youtrack.jetbrains.com/issue/JBR-2257 103 | .idea/$CACHE_FILE$ 104 | 105 | # CodeStream plugin 106 | # https://plugins.jetbrains.com/plugin/12206-codestream 107 | .idea/codestream.xml 108 | 109 | ### macOS ### 110 | # General 111 | .DS_Store 112 | .AppleDouble 113 | .LSOverride 114 | 115 | # Icon must end with two \r 116 | Icon 117 | 118 | 119 | # Thumbnails 120 | ._* 121 | 122 | # Files that might appear in the root of a volume 123 | .DocumentRevisions-V100 124 | .fseventsd 125 | .Spotlight-V100 126 | .TemporaryItems 127 | .Trashes 128 | .VolumeIcon.icns 129 | .com.apple.timemachine.donotpresent 130 | 131 | # Directories potentially created on remote AFP share 132 | .AppleDB 133 | .AppleDesktop 134 | Network Trash Folder 135 | Temporary Items 136 | .apdisk 137 | 138 | ### Rust ### 139 | # Generated by Cargo 140 | # will have compiled files and executables 141 | target/ 142 | 143 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 144 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 145 | Cargo.lock 146 | 147 | ### VisualStudioCode ### 148 | .vscode/* 149 | !.vscode/tasks.json 150 | !.vscode/launch.json 151 | *.code-workspace 152 | 153 | ### VisualStudioCode Patch ### 154 | # Ignore all local history of files 155 | .history 156 | .ionide 157 | 158 | ### vscode ### 159 | !.vscode/settings.json 160 | !.vscode/extensions.json 161 | 162 | # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,jetbrains,rust,vscode 163 | 164 | # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) 165 | 166 | .idea -------------------------------------------------------------------------------- /hello_cargo/2021-01-13.md: -------------------------------------------------------------------------------- 1 | 2 | ![Cargo](https://static01.imgkr.com/temp/8af5f61aeea5498a95e2ca6cdf777f75.png) 3 | 4 | 5 | ## 前 言 6 | 7 | > 本篇文章将介绍在`MacOS`上配置一下`Rust`开发环境,并且使用`cargo`编译一个程序。 8 | 9 | ## 介绍一下rustup 10 | 11 | > `rustup` 是rust官方的版本管理工具,应当作为安装 Rust 的首选。因为 Rust 的更新速度很快,支持的版本很多,有时新版本是不会完美兼容旧版本的,同时还支持多平台交叉编译,所以就有了 `rustup` 这个 `Rust` 工具链的管理工具。 12 | 13 | **特 性** 14 | 15 | 1. 管理安装多个官方版本的 Rust 二进制程序。 16 | 2. 配置基于目录的 Rust 工具链。 17 | 3. 安装和更新来自 Rust 的发布通道: nightly, beta 和 stable。 18 | 4. 接收来自发布通道更新的通知。 19 | 5. 从官方安装历史版本的 nightly 工具链。 20 | 6. 通过指定 stable 版本来安装。 21 | 7. 安装额外的 std 用于交叉编译。 22 | 8. 安装自定义的工具链。 23 | 9. 独立每个安装的 Cargo metadata。 24 | 10. 校验下载的 hash 值。 25 | 11. 校验签名 (如果 GPG 存在)。 26 | 12. 断点续传。 27 | 13. 只依赖 bash, curl 和常见 unix 工具。 28 | 14. 支持 Linux, OS X, Windows(via MSYS2)。 29 | 30 | 使用`rustup`安装的时候,他会帮你安装一下工具: 31 | 32 | - `rustc` 编译器 33 | - `rust-std` 标准库 34 | - `cargo` 包管理工具 35 | - `rust-doc` 说明文档 36 | 37 | ## Hello, Cargo! 38 | 39 | `Cargo` 是 `Rust` 的构建系统和包管理器。大多数 `Rustacean` 们使用 Cargo 来管理他们的 Rust 项目,因为它可以为你处理很多任务,比如构建代码、下载依赖库并编译这些库。 40 | 41 | - 检测是否安装输入命令`cargo --version` 42 | 43 | 1. 创建一个基于`cargo`的项目,在你需要工作的目录输入下面命令 44 | 45 | ``` shell 46 | $ cargo new hello_cargo 47 | $ cd hello_cargo 48 | ``` 49 | ![步骤截图](https://tva1.sinaimg.cn/large/008eGmZEgy1gmm424ai02j30vl0ozth6.jpg) 50 | 51 | 2. 先不急着coding,先看看`Cargo.toml`文件里面是啥 52 | 53 | ```toml 54 | 55 | [package] 56 | # 项目名字 57 | name = "hello_cargo" 58 | # 项目版本 59 | version = "0.1.0" 60 | # 开发者信息 61 | authors = ["Dings "] 62 | # edition 字段表明代码应该使用哪个版本编译。如果该字段不存在,其默认为 2015 以提供后向兼容性 63 | edition = "2018" 64 | 65 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 66 | 67 | # 项目依赖的相关配置 68 | [dependencies] 69 | 70 | ``` 71 | **相关命令** 72 | - `cargo build` 构建了项目 73 | - `cargo run` 编译和运行 74 | - `cargo check` 快速检查代码确保其可以编译 75 | - `cargo build --release` 来优化编译项目 76 | ![相关截图](https://tva1.sinaimg.cn/large/008eGmZEgy1gmm4okc7g4j30vi0ew76r.jpg) 77 | 78 | **目录树** 79 | ```shell 80 | . 81 | ├── Cargo.lock 82 | ├── Cargo.toml #项目配置文件 83 | ├── src 84 | │ └── main.rs #源代码 85 | └── target 86 | ├── debug 87 | │ ├── build 88 | │ ├── deps 89 | │ │ ├── hello_cargo 90 | │ │ ├── hello_cargo-78eae60a3411fe6a.d 91 | │ │ ├── hello_cargo.d 92 | │ │ ├── hello_cargo.dSYM 93 | │ │ │ └── Contents 94 | │ │ │ ├── Info.plist 95 | │ │ │ └── Resources 96 | │ │ │ └── DWARF 97 | │ │ │ └── hello_cargo 98 | │ │ └── libhello_cargo-78eae60a3411fe6a.rmeta 99 | │ ├── examples 100 | │ ├── hello_cargo # 通过cargo build命令编译的文件 101 | │ ├── hello_cargo.d 102 | │ ├── hello_cargo.dSYM -> deps/hello_cargo.dSYM 103 | │ └── incremental 104 | │ ├── hello_cargo-26qis3iilpuur 105 | │ │ ├── s-fuvsuy23na-r43ojw-2t182s5q0dt12 106 | │ │ │ ├── 2jvy8xluqgkv4hsc.o 107 | │ │ │ ├── 43rml2340ue2u3or.o 108 | │ │ │ ├── 4gff6lewv558d7hd.o 109 | │ │ │ ├── 5e4yktp11yqh41nh.o 110 | │ │ │ ├── 9ozf2iny9myyxf1.o 111 | │ │ │ ├── aquy2j79dx7cao6.o 112 | │ │ │ ├── dep-graph.bin 113 | │ │ │ ├── dw27ip9j49wp13a.o 114 | │ │ │ ├── query-cache.bin 115 | │ │ │ ├── s1ldp7xzfsqu1qa.o 116 | │ │ │ └── work-products.bin 117 | │ │ └── s-fuvsuy23na-r43ojw.lock 118 | │ └── hello_cargo-2bfwcl0xfqfyn 119 | │ ├── s-fuvszg9edb-16ck9sg-1v61ikyjcmqbe 120 | │ │ ├── dep-graph.bin 121 | │ │ ├── query-cache.bin 122 | │ │ └── work-products.bin 123 | │ └── s-fuvszg9edb-16ck9sg.lock 124 | └── rls 125 | ├── CACHEDIR.TAG 126 | └── debug 127 | ├── build 128 | ├── deps 129 | │ ├── hello_cargo-78eae60a3411fe6a.d 130 | │ ├── hello_cargo-9bf68345dc6a6cf2.d 131 | │ ├── libhello_cargo-78eae60a3411fe6a.rmeta 132 | │ ├── libhello_cargo-9bf68345dc6a6cf2.rmeta 133 | │ └── save-analysis 134 | │ ├── hello_cargo-78eae60a3411fe6a.json 135 | │ └── hello_cargo-9bf68345dc6a6cf2.json 136 | ├── examples 137 | └── incremental 138 | ├── hello_cargo-2bfwcl0xfqfyn 139 | │ ├── s-fuvsuxo21z-1cp5obv-2myzxclgxxcne 140 | │ │ ├── dep-graph.bin 141 | │ │ ├── query-cache.bin 142 | │ │ └── work-products.bin 143 | │ └── s-fuvsuxo21z-1cp5obv.lock 144 | └── hello_cargo-2krn1xdg5hbrp 145 | ├── s-fuvsuxonks-ktua5r-kffuaq863tw9 146 | │ ├── dep-graph.bin 147 | │ ├── query-cache.bin 148 | │ └── work-products.bin 149 | └── s-fuvsuxonks-ktua5r.lock 150 | 151 | 27 directories, 42 files 152 | ``` 153 | ## 把 Cargo 当作习惯 154 | > 对于简单项目, Cargo 并不比 rustc 提供了更多的优势,不过随着开发的深入,终将证明其价值。对于拥有多个 crate 的复杂项目,交给 Cargo 来协调构建将简单的多。 155 | 156 | - 上面引用官方文档一段的话👍 157 | 158 | ## 相关资料 159 | 160 | - https://github.com/rust-lang/book 161 | - https://github.com/higker/learning-rust-zh --------------------------------------------------------------------------------