From 293e312502a8b18f9a56e7dd2b3d11bdaba6c556 Mon Sep 17 00:00:00 2001 From: Unisko PENG Date: Tue, 11 Apr 2023 17:27:47 +0800 Subject: [PATCH] reorganized the directories --- add/Cargo.toml | 6 -- add/add_one/Cargo.toml | 9 --- add/add_one/src/lib.rs | 14 ---- add/adder/Cargo.toml | 10 --- add/adder/src/main.rs | 6 -- adder/Cargo.toml | 8 -- adder/src/lib.rs | 17 ----- adder/tests/common/mod.rs | 3 - adder/tests/integration_test.rs | 9 --- aggregator/Cargo.toml | 8 -- aggregator/src/bin/test_case.rs | 3 - aggregator/src/lib.rs | 56 -------------- aggregator/src/main.rs | 54 ------------- art/Cargo.toml | 8 -- art/src/kinds.rs | 15 ---- art/src/lib.rs | 10 --- art/src/utils.rs | 9 --- assert_demo/Cargo.toml | 8 -- assert_demo/src/lib.rs | 43 ----------- associated_type/Cargo.lock | 7 -- associated_type/Cargo.toml | 8 -- associated_type/src/main.rs | 3 - branches/Cargo.toml | 8 -- branches/src/main.rs | 7 -- cargo_features_demo/Cargo.toml | 9 --- cargo_features_demo/src/lib.rs | 21 ------ cargo_features_demo/src/main.rs | 8 -- cargo_features_demo/src/tests.rs | 6 -- clippy_demo/Cargo.toml | 8 -- clippy_demo/src/main.rs | 5 -- closure-example/Cargo.toml | 8 -- closure-example/src/main.rs | 22 ------ closure_demo/Cargo.toml | 8 -- closure_demo/src/main.rs | 57 -------------- concur_demo/Cargo.toml | 8 -- concur_demo/src/main.rs | 14 ---- cons_list_demo/Cargo.toml | 8 -- cons_list_demo/src/main.rs | 24 ------ declarative_macro/Cargo.lock | 7 -- declarative_macro/Cargo.toml | 8 -- declarative_macro/src/main.rs | 4 - derive_macro_comsumer/Cargo.toml | 10 --- derive_macro_comsumer/src/main.rs | 9 --- disambiguation/Cargo.toml | 8 -- disambiguation/src/main.rs | 21 ------ dst/Cargo.toml | 8 -- dst/src/main.rs | 4 - encapsulation_demo/Cargo.lock | 7 -- encapsulation_demo/Cargo.toml | 8 -- encapsulation_demo/src/lib.rs | 34 --------- enum_demo/Cargo.toml | 8 -- enum_demo/src/main.rs | 7 -- error_handling_demo/Cargo.toml | 8 -- error_handling_demo/src/main.rs | 9 --- extern_code/Cargo.toml | 8 -- extern_code/src/main.rs | 17 ----- fah_to_cels/Cargo.toml | 8 -- fah_to_cels/src/main.rs | 67 ----------------- fn_pattn_demo/Cargo.toml | 8 -- fn_pattn_demo/src/main.rs | 8 -- for_demo/Cargo.toml | 8 -- for_demo/src/main.rs | 7 -- func_pointer/Cargo.toml | 8 -- func_pointer/src/main.rs | 30 -------- functions/Cargo.toml | 8 -- functions/src/main.rs | 9 --- generics_demo/Cargo.toml | 8 -- generics_demo/src/main.rs | 14 ---- guessing_game/Cargo.toml | 11 --- guessing_game/README.md | 3 - guessing_game/src/main.rs | 64 ---------------- hashmap_demo/Cargo.toml | 8 -- hashmap_demo/src/main.rs | 14 ---- hello/404.html | 11 --- hello/Cargo.toml | 8 -- hello/hello.html | 11 --- hello/src/lib.rs | 92 ----------------------- hello/src/main.rs | 46 ------------ hello_cargo/Cargo.toml | 8 -- hello_cargo/src/main.rs | 4 - hello_macro/Cargo.toml | 8 -- hello_macro/hello_macro_derive/Cargo.toml | 12 --- hello_macro/hello_macro_derive/src/lib.rs | 26 ------- hello_macro/src/lib.rs | 3 - hello_macro_derive/Cargo.toml | 8 -- hello_macro_derive/src/lib.rs | 14 ---- hello_world/Cargo.toml | 8 -- hello_world/src/main.rs | 4 - if_let_demo/Cargo.toml | 8 -- if_let_demo/src/main.rs | 22 ------ iterator_demo/Cargo.toml | 8 -- iterator_demo/src/lib.rs | 35 --------- iterator_demo/src/main.rs | 7 -- iterator_demo/src/tests.rs | 35 --------- lifetimes_demo/Cargo.toml | 8 -- lifetimes_demo/src/main.rs | 23 ------ limit_tracker/Cargo.toml | 8 -- limit_tracker/src/lib.rs | 77 ------------------- loops/Cargo.toml | 8 -- loops/src/main.rs | 7 -- lyrics_of_xmas_carol/Cargo.toml | 8 -- lyrics_of_xmas_carol/src/main.rs | 60 --------------- minigrep/Cargo.toml | 14 ---- minigrep/poem.txt | 9 --- minigrep/src/data_structures.rs | 33 -------- minigrep/src/lib.rs | 57 -------------- minigrep/src/main.rs | 19 ----- minigrep/src/tests.rs | 28 ------- mp_demo/Cargo.lock | 7 -- mp_demo/Cargo.toml | 8 -- mp_demo/src/main.rs | 43 ----------- mutex_demo/Cargo.lock | 7 -- mutex_demo/Cargo.toml | 8 -- mutex_demo/src/main.rs | 27 ------- neo_simple_blog/Cargo.lock | 7 -- neo_simple_blog/Cargo.toml | 8 -- neo_simple_blog/src/lib.rs | 43 ----------- neo_simple_blog/src/main.rs | 15 ---- never_type/Cargo.toml | 8 -- never_type/src/main.rs | 7 -- newtype/Cargo.toml | 8 -- newtype/src/main.rs | 13 ---- nth_fibonacci/Cargo.toml | 9 --- nth_fibonacci/src/main.rs | 47 ------------ operator_overloading/Cargo.toml | 8 -- operator_overloading/src/main.rs | 45 ----------- ownership_demo/Cargo.toml | 8 -- ownership_demo/src/main.rs | 42 ----------- pattern_syntax_demo/Cargo.toml | 8 -- pattern_syntax_demo/src/main.rs | 17 ----- raw_idenitifers/Cargo.toml | 8 -- raw_idenitifers/src/main.rs | 7 -- raw_pointers/Cargo.toml | 8 -- raw_pointers/src/main.rs | 11 --- rectangles/Cargo.toml | 8 -- rectangles/src/main.rs | 52 ------------- ref_cycle_demo/Cargo.toml | 8 -- ref_cycle_demo/src/main.rs | 42 ----------- references_demo/Cargo.toml | 8 -- references_demo/src/main.rs | 11 --- refutable_demo/Cargo.toml | 8 -- refutable_demo/src/main.rs | 5 -- restaurant/Cargo.toml | 8 -- restaurant/src/front_of_house.rs | 1 - restaurant/src/front_of_house/hosting.rs | 1 - restaurant/src/lib.rs | 28 ------- returning_closure/Cargo.toml | 8 -- returning_closure/src/main.rs | 7 -- rustfix_demo/Cargo.toml | 8 -- rustfix_demo/src/main.rs | 7 -- safe_abstraction/Cargo.toml | 8 -- safe_abstraction/src/main.rs | 12 --- simple_blog/Cargo.lock | 7 -- simple_blog/Cargo.toml | 8 -- simple_blog/src/lib.rs | 82 -------------------- simple_blog/src/main.rs | 17 ----- simple_gui/Cargo.lock | 7 -- simple_gui/Cargo.toml | 8 -- simple_gui/src/lib.rs | 31 -------- simple_gui/src/main.rs | 27 ------- sp_demos/Cargo.toml | 8 -- sp_demos/src/main.rs | 4 - static_variable/Cargo.toml | 8 -- static_variable/src/main.rs | 15 ---- string_demo/Cargo.toml | 8 -- string_demo/src/main.rs | 11 --- structs_demo/Cargo.toml | 8 -- supertrait/Cargo.toml | 8 -- supertrait/src/main.rs | 32 -------- traits_demo/src/aggregator/lib.rs | 29 ------- tree_demo/Cargo.toml | 8 -- tree_demo/src/main.rs | 51 ------------- type_aliases/Cargo.toml | 8 -- type_aliases/src/main.rs | 20 ----- unsafe_functions/Cargo.toml | 8 -- unsafe_functions/src/main.rs | 7 -- unsafe_trait/Cargo.toml | 8 -- unsafe_trait/src/main.rs | 9 --- variables/Cargo.toml | 8 -- variables/src/main.rs | 29 ------- vec_demo/Cargo.toml | 8 -- vec_demo/src/main.rs | 26 ------- while_let_demo/Cargo.toml | 8 -- while_let_demo/src/main.rs | 5 -- 184 files changed, 2918 deletions(-) delete mode 100644 add/Cargo.toml delete mode 100644 add/add_one/Cargo.toml delete mode 100644 add/add_one/src/lib.rs delete mode 100644 add/adder/Cargo.toml delete mode 100644 add/adder/src/main.rs delete mode 100644 adder/Cargo.toml delete mode 100644 adder/src/lib.rs delete mode 100644 adder/tests/common/mod.rs delete mode 100644 adder/tests/integration_test.rs delete mode 100644 aggregator/Cargo.toml delete mode 100644 aggregator/src/bin/test_case.rs delete mode 100644 aggregator/src/lib.rs delete mode 100644 aggregator/src/main.rs delete mode 100644 art/Cargo.toml delete mode 100644 art/src/kinds.rs delete mode 100644 art/src/lib.rs delete mode 100644 art/src/utils.rs delete mode 100644 assert_demo/Cargo.toml delete mode 100644 assert_demo/src/lib.rs delete mode 100644 associated_type/Cargo.lock delete mode 100644 associated_type/Cargo.toml delete mode 100644 associated_type/src/main.rs delete mode 100644 branches/Cargo.toml delete mode 100644 branches/src/main.rs delete mode 100644 cargo_features_demo/Cargo.toml delete mode 100644 cargo_features_demo/src/lib.rs delete mode 100644 cargo_features_demo/src/main.rs delete mode 100644 cargo_features_demo/src/tests.rs delete mode 100644 clippy_demo/Cargo.toml delete mode 100644 clippy_demo/src/main.rs delete mode 100644 closure-example/Cargo.toml delete mode 100644 closure-example/src/main.rs delete mode 100644 closure_demo/Cargo.toml delete mode 100644 closure_demo/src/main.rs delete mode 100644 concur_demo/Cargo.toml delete mode 100644 concur_demo/src/main.rs delete mode 100644 cons_list_demo/Cargo.toml delete mode 100644 cons_list_demo/src/main.rs delete mode 100644 declarative_macro/Cargo.lock delete mode 100644 declarative_macro/Cargo.toml delete mode 100644 declarative_macro/src/main.rs delete mode 100644 derive_macro_comsumer/Cargo.toml delete mode 100644 derive_macro_comsumer/src/main.rs delete mode 100644 disambiguation/Cargo.toml delete mode 100644 disambiguation/src/main.rs delete mode 100644 dst/Cargo.toml delete mode 100644 dst/src/main.rs delete mode 100644 encapsulation_demo/Cargo.lock delete mode 100644 encapsulation_demo/Cargo.toml delete mode 100644 encapsulation_demo/src/lib.rs delete mode 100644 enum_demo/Cargo.toml delete mode 100644 enum_demo/src/main.rs delete mode 100644 error_handling_demo/Cargo.toml delete mode 100644 error_handling_demo/src/main.rs delete mode 100644 extern_code/Cargo.toml delete mode 100644 extern_code/src/main.rs delete mode 100644 fah_to_cels/Cargo.toml delete mode 100644 fah_to_cels/src/main.rs delete mode 100644 fn_pattn_demo/Cargo.toml delete mode 100644 fn_pattn_demo/src/main.rs delete mode 100644 for_demo/Cargo.toml delete mode 100644 for_demo/src/main.rs delete mode 100644 func_pointer/Cargo.toml delete mode 100644 func_pointer/src/main.rs delete mode 100644 functions/Cargo.toml delete mode 100644 functions/src/main.rs delete mode 100644 generics_demo/Cargo.toml delete mode 100644 generics_demo/src/main.rs delete mode 100644 guessing_game/Cargo.toml delete mode 100644 guessing_game/README.md delete mode 100644 guessing_game/src/main.rs delete mode 100644 hashmap_demo/Cargo.toml delete mode 100644 hashmap_demo/src/main.rs delete mode 100644 hello/404.html delete mode 100644 hello/Cargo.toml delete mode 100644 hello/hello.html delete mode 100644 hello/src/lib.rs delete mode 100644 hello/src/main.rs delete mode 100644 hello_cargo/Cargo.toml delete mode 100644 hello_cargo/src/main.rs delete mode 100644 hello_macro/Cargo.toml delete mode 100644 hello_macro/hello_macro_derive/Cargo.toml delete mode 100644 hello_macro/hello_macro_derive/src/lib.rs delete mode 100644 hello_macro/src/lib.rs delete mode 100644 hello_macro_derive/Cargo.toml delete mode 100644 hello_macro_derive/src/lib.rs delete mode 100644 hello_world/Cargo.toml delete mode 100644 hello_world/src/main.rs delete mode 100644 if_let_demo/Cargo.toml delete mode 100644 if_let_demo/src/main.rs delete mode 100644 iterator_demo/Cargo.toml delete mode 100644 iterator_demo/src/lib.rs delete mode 100644 iterator_demo/src/main.rs delete mode 100644 iterator_demo/src/tests.rs delete mode 100644 lifetimes_demo/Cargo.toml delete mode 100644 lifetimes_demo/src/main.rs delete mode 100644 limit_tracker/Cargo.toml delete mode 100644 limit_tracker/src/lib.rs delete mode 100644 loops/Cargo.toml delete mode 100644 loops/src/main.rs delete mode 100644 lyrics_of_xmas_carol/Cargo.toml delete mode 100644 lyrics_of_xmas_carol/src/main.rs delete mode 100644 minigrep/Cargo.toml delete mode 100644 minigrep/poem.txt delete mode 100644 minigrep/src/data_structures.rs delete mode 100644 minigrep/src/lib.rs delete mode 100644 minigrep/src/main.rs delete mode 100644 minigrep/src/tests.rs delete mode 100644 mp_demo/Cargo.lock delete mode 100644 mp_demo/Cargo.toml delete mode 100644 mp_demo/src/main.rs delete mode 100644 mutex_demo/Cargo.lock delete mode 100644 mutex_demo/Cargo.toml delete mode 100644 mutex_demo/src/main.rs delete mode 100644 neo_simple_blog/Cargo.lock delete mode 100644 neo_simple_blog/Cargo.toml delete mode 100644 neo_simple_blog/src/lib.rs delete mode 100644 neo_simple_blog/src/main.rs delete mode 100644 never_type/Cargo.toml delete mode 100644 never_type/src/main.rs delete mode 100644 newtype/Cargo.toml delete mode 100644 newtype/src/main.rs delete mode 100644 nth_fibonacci/Cargo.toml delete mode 100644 nth_fibonacci/src/main.rs delete mode 100644 operator_overloading/Cargo.toml delete mode 100644 operator_overloading/src/main.rs delete mode 100644 ownership_demo/Cargo.toml delete mode 100644 ownership_demo/src/main.rs delete mode 100644 pattern_syntax_demo/Cargo.toml delete mode 100644 pattern_syntax_demo/src/main.rs delete mode 100644 raw_idenitifers/Cargo.toml delete mode 100644 raw_idenitifers/src/main.rs delete mode 100644 raw_pointers/Cargo.toml delete mode 100644 raw_pointers/src/main.rs delete mode 100644 rectangles/Cargo.toml delete mode 100644 rectangles/src/main.rs delete mode 100644 ref_cycle_demo/Cargo.toml delete mode 100644 ref_cycle_demo/src/main.rs delete mode 100644 references_demo/Cargo.toml delete mode 100644 references_demo/src/main.rs delete mode 100644 refutable_demo/Cargo.toml delete mode 100644 refutable_demo/src/main.rs delete mode 100644 restaurant/Cargo.toml delete mode 100644 restaurant/src/front_of_house.rs delete mode 100644 restaurant/src/front_of_house/hosting.rs delete mode 100644 restaurant/src/lib.rs delete mode 100644 returning_closure/Cargo.toml delete mode 100644 returning_closure/src/main.rs delete mode 100644 rustfix_demo/Cargo.toml delete mode 100644 rustfix_demo/src/main.rs delete mode 100644 safe_abstraction/Cargo.toml delete mode 100644 safe_abstraction/src/main.rs delete mode 100644 simple_blog/Cargo.lock delete mode 100644 simple_blog/Cargo.toml delete mode 100644 simple_blog/src/lib.rs delete mode 100644 simple_blog/src/main.rs delete mode 100644 simple_gui/Cargo.lock delete mode 100644 simple_gui/Cargo.toml delete mode 100644 simple_gui/src/lib.rs delete mode 100644 simple_gui/src/main.rs delete mode 100644 sp_demos/Cargo.toml delete mode 100644 sp_demos/src/main.rs delete mode 100644 static_variable/Cargo.toml delete mode 100644 static_variable/src/main.rs delete mode 100644 string_demo/Cargo.toml delete mode 100644 string_demo/src/main.rs delete mode 100644 structs_demo/Cargo.toml delete mode 100644 supertrait/Cargo.toml delete mode 100644 supertrait/src/main.rs delete mode 100644 traits_demo/src/aggregator/lib.rs delete mode 100644 tree_demo/Cargo.toml delete mode 100644 tree_demo/src/main.rs delete mode 100644 type_aliases/Cargo.toml delete mode 100644 type_aliases/src/main.rs delete mode 100644 unsafe_functions/Cargo.toml delete mode 100644 unsafe_functions/src/main.rs delete mode 100644 unsafe_trait/Cargo.toml delete mode 100644 unsafe_trait/src/main.rs delete mode 100644 variables/Cargo.toml delete mode 100644 variables/src/main.rs delete mode 100644 vec_demo/Cargo.toml delete mode 100644 vec_demo/src/main.rs delete mode 100644 while_let_demo/Cargo.toml delete mode 100644 while_let_demo/src/main.rs diff --git a/add/Cargo.toml b/add/Cargo.toml deleted file mode 100644 index 1448801..0000000 --- a/add/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[workspace] - -members = [ - "adder", - "add_one", -] diff --git a/add/add_one/Cargo.toml b/add/add_one/Cargo.toml deleted file mode 100644 index 66ee46a..0000000 --- a/add/add_one/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "add_one" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rand = "^0.8.4" diff --git a/add/add_one/src/lib.rs b/add/add_one/src/lib.rs deleted file mode 100644 index 8eff881..0000000 --- a/add/add_one/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add_one(x: i32) -> i32 { - x + 1 -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add_one(2); - assert_eq!(result, 3); - } -} diff --git a/add/adder/Cargo.toml b/add/adder/Cargo.toml deleted file mode 100644 index 5ff08a7..0000000 --- a/add/adder/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "adder" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -add_one = { path = "../add_one" } -rand = "0.8.4" diff --git a/add/adder/src/main.rs b/add/adder/src/main.rs deleted file mode 100644 index b4153a8..0000000 --- a/add/adder/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -use add_one::add_one; - -fn main() { - let num = 10; - println!("你好,世界!\n\t{num} 加 1 为 {}!", add_one(num)); -} diff --git a/adder/Cargo.toml b/adder/Cargo.toml deleted file mode 100644 index b7d36d4..0000000 --- a/adder/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "adder" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/adder/src/lib.rs b/adder/src/lib.rs deleted file mode 100644 index c1d0c22..0000000 --- a/adder/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -pub fn add_two(a: i32) -> i32 { - internal_add(a, 2) -} - -fn internal_add(a: i32, b: i32) -> i32 { - a + b -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn internal() { - assert_eq! (4, internal_add(2, 2)); - } -} diff --git a/adder/tests/common/mod.rs b/adder/tests/common/mod.rs deleted file mode 100644 index 503f4f8..0000000 --- a/adder/tests/common/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn setup() { - println! ("特定于库测试的一些设置代码,将放在这里"); -} diff --git a/adder/tests/integration_test.rs b/adder/tests/integration_test.rs deleted file mode 100644 index c56ed2c..0000000 --- a/adder/tests/integration_test.rs +++ /dev/null @@ -1,9 +0,0 @@ -use adder; - -mod common; - -#[test] -fn it_adds_two() { - common::setup(); - assert_eq! (6, adder::add_two(4)); -} diff --git a/aggregator/Cargo.toml b/aggregator/Cargo.toml deleted file mode 100644 index 27d4889..0000000 --- a/aggregator/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "aggregator" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/aggregator/src/bin/test_case.rs b/aggregator/src/bin/test_case.rs deleted file mode 100644 index 3b69746..0000000 --- a/aggregator/src/bin/test_case.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println! ("媒体聚合器"); -} diff --git a/aggregator/src/lib.rs b/aggregator/src/lib.rs deleted file mode 100644 index 16246ae..0000000 --- a/aggregator/src/lib.rs +++ /dev/null @@ -1,56 +0,0 @@ -pub trait Summary { - fn summarize_author(&self) -> String; - - fn summarize(&self) -> String { - format! ("(了解更多来自 {} ......)", self.summarize_author()) - } -} - -pub struct NewsArticle { - pub headline: String, - pub location: String, - pub author: String, - pub content: String, -} - -impl Summary for NewsArticle { - fn summarize_author(&self) -> String { - format! ("{}", self.author) - } -} - -pub struct Tweet { - pub username: String, - pub content: String, - pub reply: bool, - pub retweet: bool, -} - -impl Summary for Tweet { - fn summarize_author(&self) -> String { - format! ("@{}", self.username) - } -} - -use std::fmt::Display; - -pub struct Pair { - pub x: T, - pub y: T, -} - -impl Pair { - pub fn new(x: T, y: T) -> Self { - Self { x, y } - } -} - -impl Pair { - pub fn cmp_display(&self) { - if self.x >= self.y { - println! ("极大数为 x = {}", self.x); - } else { - println! ("极大数为 y = {}", self.y); - } - } -} diff --git a/aggregator/src/main.rs b/aggregator/src/main.rs deleted file mode 100644 index 1828013..0000000 --- a/aggregator/src/main.rs +++ /dev/null @@ -1,54 +0,0 @@ -use aggregator::{Summary, Tweet, NewsArticle, Pair}; - -pub fn notify(item: &T) { - println! ("突发新闻!{}", item.summarize()); -} - -fn return_summarizable() -> impl Summary { - Tweet { - username: String::from("horse_ebooks"), - content: String::from( - "当然,如同你或许已经知道的一样,朋友们" - ), - reply: false, - retweet: false, - } -} - -fn main() { - let tweet = Tweet { - username: String::from("horse_ebooks"), - content: String::from( - "当然,跟大家已经清楚的一样了,朋友们", - ), - reply: false, - retweet: false, - }; - - println!("1 条新推文: {}", tweet.summarize()); - notify(&tweet); - - - let article = NewsArticle { - headline: String::from("企鹅队赢得斯坦利杯锦标赛!"), - location: String::from("美国,宾夕法尼亚州,匹兹堡"), - author: String::from("Iceburgh"), - content: String::from( - "匹兹堡企鹅队再度成为美国曲棍球联盟 \ - NHL 中的最佳球队。" - ), - }; - - println! ("有新文章可读!{}", article.summarize()); - notify(&article); - - println! ("1 条旧推文: {}", return_summarizable().summarize()); - - let pair = Pair::new(5, 10); - pair.cmp_display(); - - let pair = Pair::new("这是一个测试", "This is a test."); - pair.cmp_display(); - - println! ("{}", 3.to_string()); -} diff --git a/art/Cargo.toml b/art/Cargo.toml deleted file mode 100644 index 4742a18..0000000 --- a/art/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "art" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/art/src/kinds.rs b/art/src/kinds.rs deleted file mode 100644 index d5a9a30..0000000 --- a/art/src/kinds.rs +++ /dev/null @@ -1,15 +0,0 @@ -/// RYB 颜色模型下的主要颜色。 -#[derive(Debug)] -pub enum PrimaryColor { - Red, - Yellow, - Blue, -} - -/// RYB 颜色模型下的次要颜色。 -#[derive(Debug)] -pub enum SecondaryColor { - Orange, - Green, - Purple, -} diff --git a/art/src/lib.rs b/art/src/lib.rs deleted file mode 100644 index 1c2ee79..0000000 --- a/art/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! # art - 美术 -//! -//! 建模诸多美术概念的一个库。 - -pub mod kinds; -pub mod utils; - -pub use self::kinds::PrimaryColor; -pub use self::kinds::SecondaryColor; -pub use self::utils::mix; diff --git a/art/src/utils.rs b/art/src/utils.rs deleted file mode 100644 index 8de81af..0000000 --- a/art/src/utils.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::kinds::*; - -/// 结合两种等量的主要颜色,创建出 -/// 某种次要颜色。 -pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor { - // --跳过代码-- - println! ("c1: {:?}, c2: {:?}", c1, c2); - SecondaryColor::Purple -} diff --git a/assert_demo/Cargo.toml b/assert_demo/Cargo.toml deleted file mode 100644 index 3e4fdc2..0000000 --- a/assert_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "assert_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/assert_demo/src/lib.rs b/assert_demo/src/lib.rs deleted file mode 100644 index 4a2898b..0000000 --- a/assert_demo/src/lib.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub fn add_two(a: i32) -> i32 { - a + 2 -} - -pub fn nth_fibonacci(n: u64) -> u64 { - - if n == 0 || n == 1 { - return n; - } else { - return nth_fibonacci(n - 1) + nth_fibonacci(n - 2); - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn add_two_and_two() { - assert_eq! (4, add_two(2)); - } - - #[test] - fn add_three_and_two() { - assert_eq! (5, add_two(3)); - } - - #[test] - fn one_hundred() { - assert_eq! (102, add_two(100)); - } - - #[test] - fn it_works() { - assert_eq! (2 + 2, 4); - } - - #[test] - #[ignore] - fn expensive_test() { - assert_ne! (100, nth_fibonacci(50)); - } -} diff --git a/associated_type/Cargo.lock b/associated_type/Cargo.lock deleted file mode 100644 index 8b25c34..0000000 --- a/associated_type/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "associated_type" -version = "0.1.0" diff --git a/associated_type/Cargo.toml b/associated_type/Cargo.toml deleted file mode 100644 index 4e9eec7..0000000 --- a/associated_type/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "associated_type" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/associated_type/src/main.rs b/associated_type/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/associated_type/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/branches/Cargo.toml b/branches/Cargo.toml deleted file mode 100644 index 6934aa4..0000000 --- a/branches/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "branches" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/branches/src/main.rs b/branches/src/main.rs deleted file mode 100644 index d09ae5c..0000000 --- a/branches/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let condition = true; - - let number = if condition { 5 } else { "six" }; - - println! ("number 的值为:{}", number); -} diff --git a/cargo_features_demo/Cargo.toml b/cargo_features_demo/Cargo.toml deleted file mode 100644 index 2a540a2..0000000 --- a/cargo_features_demo/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "cargo_features_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -art = { path = "../art" } diff --git a/cargo_features_demo/src/lib.rs b/cargo_features_demo/src/lib.rs deleted file mode 100644 index 98097dd..0000000 --- a/cargo_features_demo/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! # Cargo 特性示例代码箱 -//! -//! `cargo_features_demo` 是令到执行某些确切计算更便利 -//! 的一些工具的集合。 -//! - -/// 将一加到所给数字。 -/// # 示例(examples) -/// -/// ``` -/// let arg = 5; -/// let answer = cargo_features_demo::add_one(arg); -/// -/// assert_eq! (6, answer); -/// ``` -pub fn add_one(x: i32) -> i32 { - x + 2 -} - -#[cfg(test)] -mod tests; diff --git a/cargo_features_demo/src/main.rs b/cargo_features_demo/src/main.rs deleted file mode 100644 index 170a783..0000000 --- a/cargo_features_demo/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -use art::mix; -use art::PrimaryColor; - -fn main() { - let red = PrimaryColor::Red; - let yellow = PrimaryColor::Yellow; - mix(red, yellow); -} diff --git a/cargo_features_demo/src/tests.rs b/cargo_features_demo/src/tests.rs deleted file mode 100644 index b65c49d..0000000 --- a/cargo_features_demo/src/tests.rs +++ /dev/null @@ -1,6 +0,0 @@ -use super::*; - -#[test] -fn five_plus_one() { - assert_eq! (7, add_one(5)); -} diff --git a/clippy_demo/Cargo.toml b/clippy_demo/Cargo.toml deleted file mode 100644 index 0d357fe..0000000 --- a/clippy_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "clippy_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/clippy_demo/src/main.rs b/clippy_demo/src/main.rs deleted file mode 100644 index 8f4c0b9..0000000 --- a/clippy_demo/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let x = std::f64::consts::PI; - let r = 8.0; - println!("圆的面积为 {}", x * r * r); -} diff --git a/closure-example/Cargo.toml b/closure-example/Cargo.toml deleted file mode 100644 index 8085ade..0000000 --- a/closure-example/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "closure-example" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/closure-example/src/main.rs b/closure-example/src/main.rs deleted file mode 100644 index 0c514f5..0000000 --- a/closure-example/src/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[derive(Debug)] -struct Rectangle { - width: u32, - height: u32, -} - -fn main() { - let mut list = [ - Rectangle { width: 10, height: 1 }, - Rectangle { width: 3, height: 5 }, - Rectangle { width: 7, height: 12 }, - ]; - - let mut sort_operations = vec! []; - let value = String::from("按照被调用到的 key"); - - list.sort_by_key(|r| { - sort_operations.push(&value); - r.width - }); - println! ("{:#?}\n{:#?}", list, sort_operations); -} diff --git a/closure_demo/Cargo.toml b/closure_demo/Cargo.toml deleted file mode 100644 index 643b4d5..0000000 --- a/closure_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "closure_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/closure_demo/src/main.rs b/closure_demo/src/main.rs deleted file mode 100644 index 974f605..0000000 --- a/closure_demo/src/main.rs +++ /dev/null @@ -1,57 +0,0 @@ -#[derive(Debug, PartialEq, Copy, Clone)] -enum ShirtColor { - Red, - Blue, -} - -struct Inventory { - shirts: Vec, -} - -impl Inventory { - fn giveaway( - &self, - user_preference: Option - ) -> ShirtColor { - user_preference.unwrap_or_else(|| self.most_stocked()) - } - - fn most_stocked(&self) -> ShirtColor { - let mut num_red = 0; - let mut num_blue = 0; - - for color in &self.shirts { - match color { - ShirtColor::Red => num_red += 1, - ShirtColor::Blue => num_blue += 1, - } - } - - if num_red > num_blue { - ShirtColor::Red - } else { - ShirtColor::Blue - } - } -} - -fn main() { - let store = Inventory { - shirts: vec! [ShirtColor::Blue, ShirtColor::Red, ShirtColor::Blue], - }; - - let user_pref1 = Some(ShirtColor::Red); - let giveaway1 = store.giveaway(user_pref1); - println! ( - "选项为 {:?} 的用户,得到了 {:?}", - user_pref1, giveaway1 - ); - - let user_pref2 = None; - let giveaway2 = store.giveaway(user_pref2); - println! ( - "选项为 {:?} 的用户得到了 {:?}", - user_pref2, giveaway2 - ); - -} diff --git a/concur_demo/Cargo.toml b/concur_demo/Cargo.toml deleted file mode 100644 index 53aebaa..0000000 --- a/concur_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "concur_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/concur_demo/src/main.rs b/concur_demo/src/main.rs deleted file mode 100644 index 886d3ec..0000000 --- a/concur_demo/src/main.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use std::thread; - -fn main() { - let v = vec! [1, 2, 3]; - - let handle = thread::spawn(move || { - println! ("这里有个矢量值:{:?}", &v); - }); - - handle.join().unwrap(); -} diff --git a/cons_list_demo/Cargo.toml b/cons_list_demo/Cargo.toml deleted file mode 100644 index d9b7875..0000000 --- a/cons_list_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "cons_list_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/cons_list_demo/src/main.rs b/cons_list_demo/src/main.rs deleted file mode 100644 index 3a8bc3e..0000000 --- a/cons_list_demo/src/main.rs +++ /dev/null @@ -1,24 +0,0 @@ -#[derive(Debug)] -enum List { - Cons(Rc>, Rc), - Nil, -} - -use crate::List::{Cons, Nil}; -use std::cell::RefCell; -use std::rc::Rc; - -fn main() { - let value = Rc::new(RefCell::new(5)); - - let a = Rc::new(Cons(Rc::clone(&value), Rc::new(Nil))); - - let b = Cons(Rc::new(RefCell::new(3)), Rc::clone(&a)); - let c = Cons(Rc::new(RefCell::new(4)), Rc::clone(&a)); - - *value.borrow_mut() += 10; - - println! ("之后的 a = {:?}", a); - println! ("之后的 b = {:?}", b); - println! ("之后的 c = {:?}", c); -} diff --git a/declarative_macro/Cargo.lock b/declarative_macro/Cargo.lock deleted file mode 100644 index 4f1c856..0000000 --- a/declarative_macro/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "declarative_macro" -version = "0.1.0" diff --git a/declarative_macro/Cargo.toml b/declarative_macro/Cargo.toml deleted file mode 100644 index aa308b2..0000000 --- a/declarative_macro/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "declarative_macro" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/declarative_macro/src/main.rs b/declarative_macro/src/main.rs deleted file mode 100644 index 65f6504..0000000 --- a/declarative_macro/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - - println!("Hello, world!"); -} diff --git a/derive_macro_comsumer/Cargo.toml b/derive_macro_comsumer/Cargo.toml deleted file mode 100644 index b7ff214..0000000 --- a/derive_macro_comsumer/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "derive_macro_comsumer" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -hello_macro = { path = "../hello_macro" } -hello_macro_derive = { path = "../hello_macro/hello_macro_derive" } diff --git a/derive_macro_comsumer/src/main.rs b/derive_macro_comsumer/src/main.rs deleted file mode 100644 index 468c30a..0000000 --- a/derive_macro_comsumer/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -use hello_macro::HelloMacro; -use hello_macro_derive::HelloMacro; - -#[derive(HelloMacro)] -struct Pancakes; - -fn main() { - Pancakes::hello_macro(); -} diff --git a/disambiguation/Cargo.toml b/disambiguation/Cargo.toml deleted file mode 100644 index 2fc552b..0000000 --- a/disambiguation/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "disambiguation" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/disambiguation/src/main.rs b/disambiguation/src/main.rs deleted file mode 100644 index a715029..0000000 --- a/disambiguation/src/main.rs +++ /dev/null @@ -1,21 +0,0 @@ -trait Animal { - fn baby_name() -> String; -} - -struct Dog; - -impl Dog { - fn baby_name() -> String { - String::from("点点") - } -} - -impl Animal for Dog { - fn baby_name() -> String { - String::from("狗崽") - } -} - -fn main() { - println! ("小狗叫做 {}", ::baby_name()); -} diff --git a/dst/Cargo.toml b/dst/Cargo.toml deleted file mode 100644 index 5d1f188..0000000 --- a/dst/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "dst" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/dst/src/main.rs b/dst/src/main.rs deleted file mode 100644 index 19bcaab..0000000 --- a/dst/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let s1: str = "致以问候!"; - let s2: str = "最近过得怎么样?"; -} diff --git a/encapsulation_demo/Cargo.lock b/encapsulation_demo/Cargo.lock deleted file mode 100644 index a420727..0000000 --- a/encapsulation_demo/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "encapsulation_demo" -version = "0.1.0" diff --git a/encapsulation_demo/Cargo.toml b/encapsulation_demo/Cargo.toml deleted file mode 100644 index d463a97..0000000 --- a/encapsulation_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "encapsulation_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/encapsulation_demo/src/lib.rs b/encapsulation_demo/src/lib.rs deleted file mode 100644 index 3fc846c..0000000 --- a/encapsulation_demo/src/lib.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -pub struct AveragedCollection { - list: Vec, - average: f64, -} - -impl AveragedCollection { - pub fn add(&mut self, value: i32) { - self.list.push(value); - self.update_average(); - } - - pub fn remove(&mut self) -> Option { - let result = self.list.pop(); - match result { - Some(value) => { - self.update_average(); - Some(value) - } - None => None, - } - } - - pub fn average(&self) -> f64 { - self.average - } - - fn update_average(&mut self) { - let total: i32 = self.list.iter().sum(); - self.average = total as f64 / self.list.len() as f64; - } -} diff --git a/enum_demo/Cargo.toml b/enum_demo/Cargo.toml deleted file mode 100644 index 5cbbd5e..0000000 --- a/enum_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "enum_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/enum_demo/src/main.rs b/enum_demo/src/main.rs deleted file mode 100644 index 0af60c3..0000000 --- a/enum_demo/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let config_max: Option = Some(3u8); - - if let Option::Some(max) = (config_max) { - println! ("极大值被设置为了 {}", max); - } -} diff --git a/error_handling_demo/Cargo.toml b/error_handling_demo/Cargo.toml deleted file mode 100644 index 3a161fe..0000000 --- a/error_handling_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "error_handling_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/error_handling_demo/src/main.rs b/error_handling_demo/src/main.rs deleted file mode 100644 index 230c217..0000000 --- a/error_handling_demo/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main () { - use std::net::IpAddr; - - let home: IpAddr = "192.168.0.255" - .parse() - .expect("硬编码的 IP 地址应是有效的"); - - println! ("{}", home); -} diff --git a/extern_code/Cargo.toml b/extern_code/Cargo.toml deleted file mode 100644 index a271a5f..0000000 --- a/extern_code/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "extern_code" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/extern_code/src/main.rs b/extern_code/src/main.rs deleted file mode 100644 index cfbfcce..0000000 --- a/extern_code/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern "C" { - fn abs(input: i32) -> i32; - fn sqrt(input: f64) -> f64; -} - - -#[no_mangle] -pub extern "C" fn call_from_c() { - println! ("刚从 C 调用了一个 Rust 函数!"); -} - -fn main() { - unsafe { - println! ("C 语言中 -3 的绝对值为:{},3.0 的平方根为:{}", abs(-3), sqrt(3.0)); - } -} - diff --git a/fah_to_cels/Cargo.toml b/fah_to_cels/Cargo.toml deleted file mode 100644 index a4be573..0000000 --- a/fah_to_cels/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "fah_to_cels" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/fah_to_cels/src/main.rs b/fah_to_cels/src/main.rs deleted file mode 100644 index af6d21f..0000000 --- a/fah_to_cels/src/main.rs +++ /dev/null @@ -1,67 +0,0 @@ -use std::io; -use std::process; - -fn fah_to_cels(f: f32) -> f32 { - return (f - 32.0) / 1.8; -} - -fn cels_to_fah(c: f32) -> f32 { - return c * 1.8 + 32.0; -} - -fn main() { - println! ("法式温度与摄氏温度之间的转换"); - - loop { - println! ("\n-----------------\n请选择: - '1'-摄氏温度/'2'-法式温度/'Q'/\"quit\" 退出程序。 - '1'/'2'/'Q'/\"quit\"[1]:"); - - let mut temp_type = String::new(); - - io::stdin() - .read_line(&mut temp_type) - .expect("读取输入失败!"); - - let temp_type = temp_type.trim(); - - if temp_type.eq("Q") || temp_type.eq("quit") { process::exit(0); } - - if ! temp_type.eq("1") && ! temp_type.eq("2") && ! temp_type.eq("") { - println! ("无效输入,请输入 '1'、'2'、'Q'、\"quit\",或直接按下回车键"); - continue; - } - - if temp_type.eq("1") || temp_type.eq("") { - println! ("请输入要转换的摄氏温度:"); - let temp = get_temp_input(); - - println! ("摄氏温度: {:.2}°C,约为法氏温度:{:.2}°F", temp, cels_to_fah(temp)); - } - - if temp_type.eq("2") { - println! ("请输入要转换的法氏温度:"); - let temp = get_temp_input(); - - println! ("法氏温度:{:.2}°F,约为摄氏温度:{:.2}°C", temp, fah_to_cels(temp)); - } - } -} - -fn get_temp_input() -> f32 { - return loop { - let mut tmp = String::new(); - - io::stdin() - .read_line(&mut tmp) - .expect("读取输入失败"); - - match tmp.trim().parse() { - Ok(num) => { break num }, - Err(_) => { - println! ("请输入一个浮点数,比如 -10.0, 15.6"); - continue - } - }; - }; -} diff --git a/fn_pattn_demo/Cargo.toml b/fn_pattn_demo/Cargo.toml deleted file mode 100644 index 1e72a95..0000000 --- a/fn_pattn_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "fn_pattn_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/fn_pattn_demo/src/main.rs b/fn_pattn_demo/src/main.rs deleted file mode 100644 index 0fe2f3b..0000000 --- a/fn_pattn_demo/src/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn print_coordinates(&(x, y): &(i32, i32)) { - println!("当前坐标:({}, {})", x, y); -} - -fn main() { - let point = (3, -5); - print_coordinates(&point); -} diff --git a/for_demo/Cargo.toml b/for_demo/Cargo.toml deleted file mode 100644 index fac497a..0000000 --- a/for_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "for_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/for_demo/src/main.rs b/for_demo/src/main.rs deleted file mode 100644 index 14f624c..0000000 --- a/for_demo/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let v = vec! ['a', 'b', 'c']; - - for (index, value) in v.iter().enumerate() { - println! ("{} 处于索引 {} 处", value, index); - } -} diff --git a/func_pointer/Cargo.toml b/func_pointer/Cargo.toml deleted file mode 100644 index 0758072..0000000 --- a/func_pointer/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "func_pointer" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/func_pointer/src/main.rs b/func_pointer/src/main.rs deleted file mode 100644 index b17345c..0000000 --- a/func_pointer/src/main.rs +++ /dev/null @@ -1,30 +0,0 @@ -fn add_one(x: i32) -> i32 { - x + 1 -} - -fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { - f(arg) + f(arg) -} - - -fn main() { - let answer = do_twice(add_one, 5); - - println! ("答案为:{}", answer); - - let list_of_numbers = vec! [1, 2, 3]; - let list_of_strings: Vec = - list_of_numbers.iter().map(ToString::to_string).collect(); - - println! ("结果为:{:?}", list_of_strings); - - #[derive(Debug)] - enum Status { - Value(u32), - Stop, - } - - let mut list_of_statuses: Vec = (0u32..20).map(Status::Value).collect(); - list_of_statuses.append(&mut vec! [Status::Stop]); - println! ("list_of_statuses: {:?}", list_of_statuses); -} diff --git a/functions/Cargo.toml b/functions/Cargo.toml deleted file mode 100644 index a9b5578..0000000 --- a/functions/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "functions" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/functions/src/main.rs b/functions/src/main.rs deleted file mode 100644 index a79372c..0000000 --- a/functions/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let x = plus_one(-1); - - println! ("x 的值为:{}", x); -} - -fn plus_one(x: i32) -> i32 { - x + 1 -} diff --git a/generics_demo/Cargo.toml b/generics_demo/Cargo.toml deleted file mode 100644 index 8974a0e..0000000 --- a/generics_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "generics_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/generics_demo/src/main.rs b/generics_demo/src/main.rs deleted file mode 100644 index d25919a..0000000 --- a/generics_demo/src/main.rs +++ /dev/null @@ -1,14 +0,0 @@ -enum Option_i32 { - Some(i32), - None, -} - -enum Option_f64 { - Some(f64), - None, -} - -fn main() { - let integer = Option_i32::Some(5); - let float = Option_f64::Some(5.0); -} diff --git a/guessing_game/Cargo.toml b/guessing_game/Cargo.toml deleted file mode 100644 index 80f0a08..0000000 --- a/guessing_game/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "guessing_game-xfossdotcom" -license = "MIT" -version = "0.1.1" -description = "一个在其中猜出计算机所选数字的有趣游戏。" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rand = "0.8.3" diff --git a/guessing_game/README.md b/guessing_game/README.md deleted file mode 100644 index 610c66e..0000000 --- a/guessing_game/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Readme - -这是一个作为把代码箱上传到 [crates.io](https://crates.io) 示例的 Rust 项目。 diff --git a/guessing_game/src/main.rs b/guessing_game/src/main.rs deleted file mode 100644 index 79837d3..0000000 --- a/guessing_game/src/main.rs +++ /dev/null @@ -1,64 +0,0 @@ -use rand::Rng; -use std::{cmp::Ordering, io, process}; - -pub struct Guess { - value: i32, -} - -impl Guess { - pub fn new(value: i32) -> Guess { - if value < 1 || value > 100 { - panic! ("Guess 类型值必须在 1 与 100 之间,收到的是 {}", value); - } - - Guess { value } - } - - pub fn value(&self) -> i32 { - self.value - } -} - -fn main() { - loop { - println! ("\n---猜出这个数来!---"); - - let secret_number: i32 = rand::thread_rng().gen_range(1..101); - - // println! ("随机生成的秘密数字为:{}", secret_number); - - loop { - println! ("请输入你猜的数。( ‘Q/quit’ 退出游戏)"); - - let mut guess: String = String::new(); - - io::stdin() - .read_line(&mut guess) - .expect("读取行失败......"); - - if guess.trim().eq("Q") || guess.trim().eq("quit") { process::exit(0); } - - // let guess: u32 = guess.trim().parse().expect("请输入一个数字!"); - let guess: i32 = match guess.trim().parse() { - Ok(num) => num, - Err(_) => { println! ("请输入一个数字!"); continue }, - }; - - if guess < 1 || guess > 100 { - println! ("秘密数字将在 1 和 100 之间"); - continue - } - - println! ("你猜的数为:{}", guess); - - match guess.cmp(&secret_number) { - Ordering::Less => println! ("太小了!"), - Ordering::Greater => println! ("太大了!"), - Ordering::Equal => { - println! ("你赢了!"); - break - }, - } - } - } -} diff --git a/hashmap_demo/Cargo.toml b/hashmap_demo/Cargo.toml deleted file mode 100644 index c948a8c..0000000 --- a/hashmap_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hashmap_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hashmap_demo/src/main.rs b/hashmap_demo/src/main.rs deleted file mode 100644 index dcaf432..0000000 --- a/hashmap_demo/src/main.rs +++ /dev/null @@ -1,14 +0,0 @@ -fn main() { - use std::collections::HashMap; - - let text = "hello world wonderful world"; - - let mut map = HashMap::new(); - - for word in text.split_whitespace() { - let count = map.entry(word).or_insert(0); - *count += 1; - } - - println! ("{:?}", map); -} diff --git a/hello/404.html b/hello/404.html deleted file mode 100644 index 49c36b1..0000000 --- a/hello/404.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - 你好! - - -

糟糕!

-

抱歉,我不明白你要什么。

- - diff --git a/hello/Cargo.toml b/hello/Cargo.toml deleted file mode 100644 index fb1ec2c..0000000 --- a/hello/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hello" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hello/hello.html b/hello/hello.html deleted file mode 100644 index b3d914e..0000000 --- a/hello/hello.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - 你好! - - -

你好!

-

来自 Rust 的问好

- - diff --git a/hello/src/lib.rs b/hello/src/lib.rs deleted file mode 100644 index 78e7e53..0000000 --- a/hello/src/lib.rs +++ /dev/null @@ -1,92 +0,0 @@ -use std::{ - sync::{mpsc, Arc, Mutex}, - thread, -}; - -pub struct ThreadPool { - workers: Vec, - sender: Option>, -} - -type Job = Box; - -impl ThreadPool { - /// 创建出一个新的 ThreadPool。 - /// - /// 其中的 size 为线程池中线程的数目。 - /// - /// # 终止运行 - /// - /// 这个 `new` 函数将在 size 为零时终止运行。 - pub fn new(size: usize) -> ThreadPool { - assert! (size > 0); - - let (sender, receiver) = mpsc::channel(); - - let receiver = Arc::new(Mutex::new(receiver)); - - let mut workers = Vec::with_capacity(size); - - for id in 0..size { - workers.push(Worker::new(id, Arc::clone(&receiver))); - } - - ThreadPool { - workers, - sender: Some(sender), - } - } - - pub fn execute(&self, f: F) - where - F: FnOnce() + Send + 'static, - { - let job = Box::new(f); - - self.sender.as_ref().unwrap().send(job).unwrap(); - } -} - -impl Drop for ThreadPool { - fn drop(&mut self) { - drop(self.sender.take()); - - for worker in &mut self.workers { - println! ("关闭 worker {}", worker.id); - - if let Some(thread) = worker.thread.take() { - thread.join().unwrap(); - } - } - } -} - -struct Worker { - id: usize, - thread: Option>, -} - -impl Worker { - fn new(id: usize, receiver: Arc>>) -> Worker { - let thread = thread::spawn(move || loop { - let message = receiver.lock().unwrap().recv(); - - match message { - Ok(job) => { - println! ("Worker {id} 获取到一项作业;执行中。"); - - job(); - } - Err(_) => { - println! ("Worker {id} 已断开链接;关闭中。"); - break; - } - } - }); - - Worker { - id, - thread: Some(thread), - } - } -} diff --git a/hello/src/main.rs b/hello/src/main.rs deleted file mode 100644 index b1fcbe2..0000000 --- a/hello/src/main.rs +++ /dev/null @@ -1,46 +0,0 @@ -use hello::ThreadPool; - -use std::{ - fs, - thread, - io::{prelude::*, BufReader}, - net::{TcpListener, TcpStream}, - time::Duration, -}; - -fn main() { - let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); - let pool = ThreadPool::new(4); - - for stream in listener.incoming().take(2) { - let stream = stream.unwrap(); - - pool.execute(|| { - handle_conn(stream); - }); - } - - println! ("关闭中。"); -} - -fn handle_conn(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); - let req_line = buf_reader.lines().next().unwrap().unwrap(); - - let (status_line, filename) = match &req_line[..] { - "GET / HTTP/1.1" => ( "HTTP/1.1 200 OK", "hello.html"), - "GET /sleep HTTP/1.1" => { - thread::sleep(Duration::from_secs(10)); - ("HTTP/1.1 200 0K", "hello.html") - } - _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), - }; - - let contents = fs::read_to_string(filename).unwrap(); - let length = contents.len(); - - let resp = - format! ("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); - - stream.write_all(resp.as_bytes()).unwrap(); -} diff --git a/hello_cargo/Cargo.toml b/hello_cargo/Cargo.toml deleted file mode 100644 index 19c7b36..0000000 --- a/hello_cargo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hello_cargo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hello_cargo/src/main.rs b/hello_cargo/src/main.rs deleted file mode 100644 index bfb0e05..0000000 --- a/hello_cargo/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - // 这是注释。 - println! ("Hello, Cargo!"); -} diff --git a/hello_macro/Cargo.toml b/hello_macro/Cargo.toml deleted file mode 100644 index 9b9d479..0000000 --- a/hello_macro/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hello_macro" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hello_macro/hello_macro_derive/Cargo.toml b/hello_macro/hello_macro_derive/Cargo.toml deleted file mode 100644 index 1b02fb9..0000000 --- a/hello_macro/hello_macro_derive/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "hello_macro_derive" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -proc-macro = true - -[dependencies] -syn = "1.0" -quote = "1.0" diff --git a/hello_macro/hello_macro_derive/src/lib.rs b/hello_macro/hello_macro_derive/src/lib.rs deleted file mode 100644 index e45a413..0000000 --- a/hello_macro/hello_macro_derive/src/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn; - -#[proc_macro_derive(HelloMacro)] -pub fn hello_macro_derive(input: TokenStream) -> TokenStream { - // 以语法树形式,构建出咱们可操作 Rust 代码的表示 - // Construct a representation of Rust code as a syntax tree - // that we can manipulate - let ast = syn::parse(input).unwrap(); - - // 构造出这个特质实现 - impl_hello_macro(&ast) -} - -fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream { - let name = &ast.ident; - let gen = quote! { - impl HelloMacro for #name { - fn hello_macro() { - println! ("你好,宏!我的名字叫 {}!", stringify! (#name)); - } - } - }; - gen.into() -} diff --git a/hello_macro/src/lib.rs b/hello_macro/src/lib.rs deleted file mode 100644 index e747931..0000000 --- a/hello_macro/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub trait HelloMacro { - fn hello_macro(); -} diff --git a/hello_macro_derive/Cargo.toml b/hello_macro_derive/Cargo.toml deleted file mode 100644 index 8fa4119..0000000 --- a/hello_macro_derive/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hello_macro_derive" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hello_macro_derive/src/lib.rs b/hello_macro_derive/src/lib.rs deleted file mode 100644 index 7d12d9a..0000000 --- a/hello_macro_derive/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/hello_world/Cargo.toml b/hello_world/Cargo.toml deleted file mode 100644 index 624cb06..0000000 --- a/hello_world/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "hello_world" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/hello_world/src/main.rs b/hello_world/src/main.rs deleted file mode 100644 index 96e80b1..0000000 --- a/hello_world/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - // 这是注释。 - println!("Hello, World!"); -} diff --git a/if_let_demo/Cargo.toml b/if_let_demo/Cargo.toml deleted file mode 100644 index dc397a9..0000000 --- a/if_let_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "if_let_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/if_let_demo/src/main.rs b/if_let_demo/src/main.rs deleted file mode 100644 index af9a212..0000000 --- a/if_let_demo/src/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -fn main() { - let favorite_color: Option<&str> = None; - let is_tuesday = false; - let age: Result = "34".parse(); - - if let Some(color) = favorite_color { - println! ("使用你喜欢的颜色,{color},作为背景"); - } else if is_tuesday { - println! ("周二是绿色的一天!"); - } else if let Ok(age) = age { - if age > 30 { - println! ("使用紫色作为背景色"); - } else { - println! ("使用橙色作为背景色"); - } - } else { - println! ("使用蓝色作为背景色"); - } -} diff --git a/iterator_demo/Cargo.toml b/iterator_demo/Cargo.toml deleted file mode 100644 index ac9fb49..0000000 --- a/iterator_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "iterator_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/iterator_demo/src/lib.rs b/iterator_demo/src/lib.rs deleted file mode 100644 index bea2d9c..0000000 --- a/iterator_demo/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[derive(PartialEq, Debug)] -struct Shoe { - size: u32, - style: String, -} - -fn shoes_in_size(shoes: Vec, shoe_size: u32) -> Vec { - shoes.into_iter().filter(|s| s.size == shoe_size).collect() -} - -#[cfg(test)] -mod tests; - -#[test] -fn iterator_demonstration() { - let v1 = vec! [1, 2, 3]; - - let mut v1_iter = v1.iter(); - - assert_eq! (v1_iter.next(), Some(&1)); - assert_eq! (v1_iter.next(), Some(&2)); - assert_eq! (v1_iter.next(), Some(&3)); - assert_eq! (v1_iter.next(), None); -} - -#[test] -fn iterator_sum() { - let v1 = vec! [1, 2, 3]; - - let v1_iter = v1.iter(); - - let total: i32 = v1_iter.sum(); - - assert_eq! (total, 6); -} diff --git a/iterator_demo/src/main.rs b/iterator_demo/src/main.rs deleted file mode 100644 index 00097c5..0000000 --- a/iterator_demo/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let v1 = vec! [1, 2, 3]; - - let v2: Vec<_> = v1.iter().map(|x| x + 1).collect(); - - assert_eq! (v2, vec! [2, 3, 4]); -} diff --git a/iterator_demo/src/tests.rs b/iterator_demo/src/tests.rs deleted file mode 100644 index bbdc376..0000000 --- a/iterator_demo/src/tests.rs +++ /dev/null @@ -1,35 +0,0 @@ -use super::*; - -#[test] -fn filter_by_size() { - let shoes = vec! [ - Shoe { - size: 10, - style: String::from("sneaker"), - }, - Shoe { - size: 13, - style: String::from("sandal"), - }, - Shoe { - size: 10, - style: String::from("boot"), - }, - ]; - - let in_my_size = shoes_in_size(shoes, 10); - - assert_eq! ( - in_my_size, - vec! [ - Shoe { - size: 10, - style: String::from("sneaker"), - }, - Shoe { - size: 10, - style: String::from("boot"), - }, - ] - ); -} diff --git a/lifetimes_demo/Cargo.toml b/lifetimes_demo/Cargo.toml deleted file mode 100644 index 9383aea..0000000 --- a/lifetimes_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "lifetimes_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/lifetimes_demo/src/main.rs b/lifetimes_demo/src/main.rs deleted file mode 100644 index d0bc65a..0000000 --- a/lifetimes_demo/src/main.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::fmt::Display; - -fn longest_with_an_announcement<'a, T>( - x: &'a str, - y: &'a str, - ann: T, -) -> &'a str -where - T: Display, -{ - println! ("通知!{}", ann); - if x.len() > y.len() { - x - } else { - y - } -} - -fn main() { - let result = longest_with_an_announcement("abc", "测试", "计算结果已出来。"); - - println! ("{}", result); -} diff --git a/limit_tracker/Cargo.toml b/limit_tracker/Cargo.toml deleted file mode 100644 index c7089a1..0000000 --- a/limit_tracker/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "limit_tracker" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/limit_tracker/src/lib.rs b/limit_tracker/src/lib.rs deleted file mode 100644 index 27494ae..0000000 --- a/limit_tracker/src/lib.rs +++ /dev/null @@ -1,77 +0,0 @@ -pub trait Messenger { - fn send(&self, msg: &str); -} - -pub struct LimitTracker<'a, T: Messenger> { - messenger: &'a T, - value: usize, - max: usize, -} - -impl<'a, T> LimitTracker<'a, T> -where - T: Messenger, -{ - pub fn new(messenger: &'a T, max: usize) -> LimitTracker<'a, T> { - LimitTracker { - messenger, - value: 0, - max, - } - } - - pub fn set_value(&mut self, value: usize) { - self.value = value; - - let percentage_of_max = self.value as f64 / self.max as f64; - - if percentage_of_max >= 1.0 { - self.messenger.send("出错:你已超出你的配额!"); - } else if percentage_of_max >= 0.9 { - self.messenger - .send("紧急警告:你已用掉你配额的 90% !"); - } else if percentage_of_max >= 0.75 { - self.messenger - .send("警告:你已用掉你配额的 75% !"); - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use std::cell::RefCell; - - struct MockMessenger { - sent_messages: RefCell>, - } - - impl MockMessenger { - fn new() -> MockMessenger { - MockMessenger { - sent_messages: RefCell::new(vec! []), - } - } - } - - impl Messenger for MockMessenger { - fn send(&self, message: &str) { - let mut borrow_one = self.sent_messages.borrow_mut(); - let mut borrow_two = self.sent_messages.borrow_mut(); - - borrow_one.push(String::from(message)); - borrow_two.push(String::from(message)); - } - } - - #[test] - fn it_sends_an_over_75_percent_waring_message() { - let mock_messenger = MockMessenger::new(); - let mut limit_tracker = LimitTracker::new(&mock_messenger, 100); - - limit_tracker.set_value(80); - println! ("{}", mock_messenger.sent_messages.borrow().iter().next().unwrap()); - - assert_eq! (mock_messenger.sent_messages.borrow().len(), 1); - } -} diff --git a/loops/Cargo.toml b/loops/Cargo.toml deleted file mode 100644 index 0d5dad5..0000000 --- a/loops/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "loops" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/loops/src/main.rs b/loops/src/main.rs deleted file mode 100644 index 41b6133..0000000 --- a/loops/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - for number in (1..4).rev() { - println! ("{}!", number); - } - - println! ("发射!!"); -} diff --git a/lyrics_of_xmas_carol/Cargo.toml b/lyrics_of_xmas_carol/Cargo.toml deleted file mode 100644 index f206dd8..0000000 --- a/lyrics_of_xmas_carol/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "lyrics_of_xmas_carol" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/lyrics_of_xmas_carol/src/main.rs b/lyrics_of_xmas_carol/src/main.rs deleted file mode 100644 index 7dd9c5e..0000000 --- a/lyrics_of_xmas_carol/src/main.rs +++ /dev/null @@ -1,60 +0,0 @@ -fn main() { - let days = [ - "first", - "second", - "third", - "fourth", - "fifth", - "sixth", - "seventh", - "eighth", - "nineth", - "tenth", - "eleventh", - "twelfth" - ]; - let amounts = [ - "A", - "Two", - "Three", - "Four", - "Five", - "Six", - "Seven", - "Eight", - "Nine", - "Ten", - "Eleven", - "Twelve" - ]; - let things = [ - "partridge in a pear tree", - "turtle doves", - "French hens", - "calling birds", - "golden rings", - "geese-a-laying", - "swans-a-swimming", - "maids-a-milking", - "ladies dancing", - "lords-a-leaping", - "pipers piping", - "drummers drumming", - ]; - - for num in 1..=12 { - println! ("\nOn the {} day of Christmas,\nMy true love gave to me:", - days[num-1]); - for tmp in (0..num).rev() { - if tmp == 0 && num == 1 { - println! ("{} {}.", amounts[tmp], things[tmp]); - } - if tmp == 0 && num != 1 { - println! ("And {} {}.", amounts[tmp].to_lowercase(), things[tmp]); - } - if tmp != 0 { - println! ("{} {},", amounts[tmp], things[tmp]); - } - } - } -} diff --git a/minigrep/Cargo.toml b/minigrep/Cargo.toml deleted file mode 100644 index 703598f..0000000 --- a/minigrep/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "minigrep" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] - -[profile.dev] -opt-level = 1 - -[profile.release] -opt-level = 3 diff --git a/minigrep/poem.txt b/minigrep/poem.txt deleted file mode 100644 index 8707527..0000000 --- a/minigrep/poem.txt +++ /dev/null @@ -1,9 +0,0 @@ -I'm nobody! Who are you? -Are you nobody, too? -Then there's a pair of us - don't tell! -They'd banish us, you know. - -How dreary to be somebody! -How public, like a frog -To tell your name the livelong day -To an admiring bog! diff --git a/minigrep/src/data_structures.rs b/minigrep/src/data_structures.rs deleted file mode 100644 index 5d7b678..0000000 --- a/minigrep/src/data_structures.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::env; - -pub struct Config { - pub query: String, - pub file_path: String, - pub ignore_case: bool, -} - -impl Config { - pub fn build( - mut args: impl Iterator, - ) -> Result { - args.next(); - - let query = match args.next() { - Some(arg) => arg, - None => return Err("未曾获取到查询字串"), - }; - - let file_path = match args.next() { - Some(arg) => arg, - None => return Err("未曾获取到文件路径"), - }; - - let ignore_case = env::var("IGNORE_CASE").is_ok(); - - Ok(Config { - query, - file_path, - ignore_case, - }) - } -} diff --git a/minigrep/src/lib.rs b/minigrep/src/lib.rs deleted file mode 100644 index 3b9fd7c..0000000 --- a/minigrep/src/lib.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(warnings)] -// -// this is to disable warnings. -// Comment it to enable warnings. -// -use std::error::Error; -use std::fs; -use data_structures::Config; -// -// 以下两种写法,也是可以的 -// -// use self::data_structures::Config; -// use crate::data_structures::Config; - -#[cfg(test)] -mod tests; -pub mod data_structures; - -pub fn run( - config: Config -) -> Result<(), Box> { - let contents = fs::read_to_string(config.file_path)?; - - let results: Vec<&str> = if config.ignore_case { - search_insensitive(&config.query, &contents) - } else { - search(&config.query, &contents) - }; - - for line in results { - println! ("{line}"); - } - - Ok(()) -} - -pub fn search<'a>( - query: &str, - contents: &'a str -) -> Vec<&'a str> { - contents - .lines() - .filter(|line| line.contains(query)) - .collect() -} - -pub fn search_insensitive<'a>( - query: &str, - contents: &'a str -) -> Vec<&'a str> { - let query = query.to_lowercase(); - - contents - .lines() - .filter(|line| line.to_lowercase().contains(&query)) - .collect() -} diff --git a/minigrep/src/main.rs b/minigrep/src/main.rs deleted file mode 100644 index 7af555f..0000000 --- a/minigrep/src/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::env; -use std::process; - -use minigrep::data_structures::Config; - -fn main() { - let config = Config::build(env::args()) - .unwrap_or_else(|err| { - eprintln! ("解析参数时遇到问题:{err}"); - process::exit(1); - }); - - println! ("在文件 {} 中检索:{}", config.file_path, config.query); - - if let Err(e) = minigrep::run(config) { - eprintln! ("应用程序错误:{e}"); - process::exit(1); - } -} diff --git a/minigrep/src/tests.rs b/minigrep/src/tests.rs deleted file mode 100644 index 5410559..0000000 --- a/minigrep/src/tests.rs +++ /dev/null @@ -1,28 +0,0 @@ -use super::*; - -#[test] -fn case_sensitive() { - let query = "duct"; - let contents = "\ -Rust: -safe, fast, productive. -Pick three. -Duct tape."; - - assert_eq! (vec! ["safe, fast, productive."], search(query, contents)); -} - -#[test] -fn case_insensitive() { - let query = "rUst"; - let contents = "\ -Rust: -safe, fast, productive. -Pick three. -Trust me."; - - assert_eq! ( - vec! ["Rust:", "Trust me."], - search_insensitive(query, contents) - ); -} diff --git a/mp_demo/Cargo.lock b/mp_demo/Cargo.lock deleted file mode 100644 index 3792509..0000000 --- a/mp_demo/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "mp_demo" -version = "0.1.0" diff --git a/mp_demo/Cargo.toml b/mp_demo/Cargo.toml deleted file mode 100644 index be7808c..0000000 --- a/mp_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "mp_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/mp_demo/src/main.rs b/mp_demo/src/main.rs deleted file mode 100644 index 066d2e9..0000000 --- a/mp_demo/src/main.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use std::sync::mpsc; -use std::thread; -use std::time::Duration; - -fn main() { - let (tx, rx) = mpsc::channel(); - - let tx1 = tx.clone(); - thread::spawn(move || { - let vals = vec! [ - String::from("你好"), - String::from("自"), - String::from("此"), - String::from("线程"), - ]; - - for val in vals { - tx1.send(val).unwrap(); - thread::sleep(Duration::from_millis(500)); - } - }); - - thread::spawn(move || { - let vals = vec! [ - String::from("给"), - String::from("你"), - String::from("一些别的"), - String::from("消息"), - ]; - - for val in vals { - tx.send(val).unwrap(); - thread::sleep(Duration::from_millis(500)); - } - }); - - for received in rx { - println! ("收到:{}", received); - } -} diff --git a/mutex_demo/Cargo.lock b/mutex_demo/Cargo.lock deleted file mode 100644 index 348018e..0000000 --- a/mutex_demo/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "mutex_demo" -version = "0.1.0" diff --git a/mutex_demo/Cargo.toml b/mutex_demo/Cargo.toml deleted file mode 100644 index c15b0f8..0000000 --- a/mutex_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "mutex_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/mutex_demo/src/main.rs b/mutex_demo/src/main.rs deleted file mode 100644 index d7ac6a8..0000000 --- a/mutex_demo/src/main.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use std::sync::{Arc, Mutex}; -use std::thread; - -fn main() { - let counter = Arc::new(Mutex::new(0)); - let mut handles = vec! []; - - for _ in 0..10 { - let counter = Arc::clone(&counter); - let handle = thread::spawn(move || { - let mut num = counter.lock().unwrap(); - - *num += 1; - }); - - handles.push(handle); - } - - for handle in handles { - handle.join().unwrap(); - } - - println! ("结果为:{}", *counter.lock().unwrap()); -} diff --git a/neo_simple_blog/Cargo.lock b/neo_simple_blog/Cargo.lock deleted file mode 100644 index a554162..0000000 --- a/neo_simple_blog/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "neo_simple_blog" -version = "0.1.0" diff --git a/neo_simple_blog/Cargo.toml b/neo_simple_blog/Cargo.toml deleted file mode 100644 index 501d90c..0000000 --- a/neo_simple_blog/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "neo_simple_blog" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/neo_simple_blog/src/lib.rs b/neo_simple_blog/src/lib.rs deleted file mode 100644 index 38500a6..0000000 --- a/neo_simple_blog/src/lib.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub struct Post { - content: String, -} - -pub struct DraftPost { - content: String, -} - -impl Post { - pub fn new() -> DraftPost { - DraftPost { - content: String::new(), - } - } - - pub fn content(&self) -> &str { - &self.content - } -} - -impl DraftPost { - pub fn add_text(&mut self, text: &str) { - self.content.push_str(text); - } - - pub fn request_review(self) -> PendingReviewPost { - PendingReviewPost { - content: self.content, - } - } -} - -pub struct PendingReviewPost { - content: String, -} - -impl PendingReviewPost { - pub fn approve(self) -> Post { - Post { - content: self.content, - } - } -} diff --git a/neo_simple_blog/src/main.rs b/neo_simple_blog/src/main.rs deleted file mode 100644 index 4ab39ce..0000000 --- a/neo_simple_blog/src/main.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use neo_simple_blog::Post; - -fn main() { - let mut post = Post::new(); - - post.add_text("这是一个博客帖子。"); - - let post = post.request_review(); - let post = post.approve(); - - assert_eq! ("这是一个博客帖子。", post.content()); -} diff --git a/never_type/Cargo.toml b/never_type/Cargo.toml deleted file mode 100644 index 7f1d489..0000000 --- a/never_type/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "never_type" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/never_type/src/main.rs b/never_type/src/main.rs deleted file mode 100644 index 2071f77..0000000 --- a/never_type/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - print! ("永永 "); - - loop { - print! ("远远 "); - } -} diff --git a/newtype/Cargo.toml b/newtype/Cargo.toml deleted file mode 100644 index dd63388..0000000 --- a/newtype/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "newtype" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/newtype/src/main.rs b/newtype/src/main.rs deleted file mode 100644 index 776b9d7..0000000 --- a/newtype/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::fmt; - -struct Wrapper(Vec); - -impl fmt::Display for Wrapper { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write! (f, "[{}]", self.0.join(", ")) - } -} -fn main() { - let w = Wrapper(vec! [String::from("你好"), String::from("世界")]); - println! ("w = {}", w); -} diff --git a/nth_fibonacci/Cargo.toml b/nth_fibonacci/Cargo.toml deleted file mode 100644 index 633d91a..0000000 --- a/nth_fibonacci/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "nth_fibonacci" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -num-format = "0.4.0" diff --git a/nth_fibonacci/src/main.rs b/nth_fibonacci/src/main.rs deleted file mode 100644 index f7a6fd6..0000000 --- a/nth_fibonacci/src/main.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::io; -use num_format::{Locale, ToFormattedString}; -// use std::process; - -fn nth_fibonacci(n: u64) -> u64 { - - if n == 0 || n == 1 { - return n; - } else { - return nth_fibonacci(n - 1) + nth_fibonacci(n - 2); - } -} - -fn main() { - println! ("找出第 n 个斐波拉基数"); - - 'main_loop: loop { - println! ("请输入 n: (Q/quit 退出程序)"); - - let n: u64 = loop { - let mut tmp = String::new(); - - io::stdin() - .read_line(&mut tmp) - .expect("读取输入失败!"); - - let tmp = tmp.trim(); - - if tmp.eq("Q") || tmp.eq("quit") { - // process::exit(0); - break 'main_loop; - } - - match tmp.parse() { - Ok(num) => { break num }, - Err(_) => { - println! ("请输入一个正整数!\n"); - continue; - }, - }; - }; - - println! ("第 {} 个斐波拉基数为:{}", - n, - nth_fibonacci(n).to_formatted_string(&Locale::en)); - } -} diff --git a/operator_overloading/Cargo.toml b/operator_overloading/Cargo.toml deleted file mode 100644 index 0a6eb65..0000000 --- a/operator_overloading/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "operator_overloading" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/operator_overloading/src/main.rs b/operator_overloading/src/main.rs deleted file mode 100644 index 7b7b95b..0000000 --- a/operator_overloading/src/main.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::ops::Add; - -#[derive(Debug, Copy, Clone, PartialEq)] -struct Point { - x: i32, - y: i32, -} - -impl Add for Point { - type Output = Point; - - fn add(self, other: Point) -> Point { - Point { - x: self.x + other.x, - y: self.y + other.y, - } - } -} - - -#[derive(Debug, Copy, Clone, PartialEq)] -struct Millimeters(u32); - -#[derive(Debug, Copy, Clone, PartialEq)] -struct Meters(u32); - -impl Add for Millimeters { - type Output = Millimeters; - - fn add(self, other: Meters) -> Millimeters { - Millimeters(self.0 + (other.0 * 1000)) - } -} - -fn main() { - assert_eq! ( - Point { x: 1, y: 0 } + Point { x: 2, y: 3}, - Point { x: 3, y: 3 } - ); - - assert_eq! ( - Millimeters(50) + Meters(1), - Millimeters(1050) - ); -} diff --git a/ownership_demo/Cargo.toml b/ownership_demo/Cargo.toml deleted file mode 100644 index b4df443..0000000 --- a/ownership_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "ownership_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/ownership_demo/src/main.rs b/ownership_demo/src/main.rs deleted file mode 100644 index 7bd91cc..0000000 --- a/ownership_demo/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -fn main() { - let s = String::from("The quick brown fox jumps over the lazy dog."); - - // 函数 first_word 在 String 值的切片上有效,不管是部分还是全部的切片 - let word = first_word(&s[0..6]); - println! ("{}", word); - - let word = first_word(&s[..]); - println! ("{}", word); - - // 函数 first_word 还在 String 变量的引用上有效,而 String 变量的引用 - // 与 String 值的整个切片是等价的 - let word = first_word(&s); - println! ("{}", word); - - let s_string_literal = "hello word"; - - // 函数 first_word 在字符串字面值上有效,不论是部分还是整体 - let word = first_word(&s_string_literal[0..6]); - println! ("{}", word); - - let word = first_word(&s_string_literal[..]); - println! ("{}", word); - - // 由于字符串字面值已经 是 字符串切片,因此无需切片语法,这 - // 也是有效的! - let word = first_word(s_string_literal); - - println! ("{}", word); -} - -fn first_word(s: &str) -> &str { - let bytes = s.as_bytes(); - - for (i, &item) in bytes.iter().enumerate() { - if item == b' ' { - return &s[0..i]; - } - } - - &s[..] -} diff --git a/pattern_syntax_demo/Cargo.toml b/pattern_syntax_demo/Cargo.toml deleted file mode 100644 index 240aac9..0000000 --- a/pattern_syntax_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "pattern_syntax_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/pattern_syntax_demo/src/main.rs b/pattern_syntax_demo/src/main.rs deleted file mode 100644 index 7bbf2eb..0000000 --- a/pattern_syntax_demo/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -fn main() { - enum Message { - Hello { id: u32 }, - } - - let msg = Message::Hello { id: 5 }; - - match msg { - Message::Hello { - id: id_variable @ 3..=7, - } => println! ("找到位于范围内的一个 id: {}", id_variable), - Message::Hello { id: 10..=12 } => { - println! ("找到位于另一范围的一个 {}", id); - }, - Message::Hello { id } => println! ("找到别的一个 id: {}", id), - } -} diff --git a/raw_idenitifers/Cargo.toml b/raw_idenitifers/Cargo.toml deleted file mode 100644 index 40aff17..0000000 --- a/raw_idenitifers/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "raw_idenitifers" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/raw_idenitifers/src/main.rs b/raw_idenitifers/src/main.rs deleted file mode 100644 index 61b84cf..0000000 --- a/raw_idenitifers/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn r#match(needle: &str, haystack: &str) -> bool { - haystack.contains(needle) -} - -fn main() { - assert! (r#match("foo", "foobar")); -} diff --git a/raw_pointers/Cargo.toml b/raw_pointers/Cargo.toml deleted file mode 100644 index e1b1b9e..0000000 --- a/raw_pointers/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "raw_pointers" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/raw_pointers/src/main.rs b/raw_pointers/src/main.rs deleted file mode 100644 index bff33b0..0000000 --- a/raw_pointers/src/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let mut num = 5; - - let r1 = &num as *const i32; - let r2 = &mut num as *mut i32; - - unsafe { - println! ("r1 为:{}", *r1); - println! ("r2 为:{}", *r2); - } -} diff --git a/rectangles/Cargo.toml b/rectangles/Cargo.toml deleted file mode 100644 index 703c9d9..0000000 --- a/rectangles/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rectangles" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/rectangles/src/main.rs b/rectangles/src/main.rs deleted file mode 100644 index a7aa76e..0000000 --- a/rectangles/src/main.rs +++ /dev/null @@ -1,52 +0,0 @@ -#[derive(Debug)] -struct Rectangle { - width: u32, - height: u32, -} - -impl Rectangle { - fn area(&self) -> u32 { - self.width * self.height - } - - fn width(&self) -> bool { - self.width > 0 - } - - fn can_hold(&self, other: &Rectangle) -> bool { - (self.width > other.width && self.height > other.height) || - (self.width > other.height && self.height > other.width) - } - - fn square(size: u32) -> Rectangle { - Rectangle { - width: size, - height: size, - } - } -} - -fn main() { - let rect1 = Rectangle { - width: 30, - height: 50, - }; - - let rect2 = Rectangle { - width: 10, - height: 40, - }; - - let rect3 = Rectangle { - width: 45, - height: 25, - }; - - let sq1 = Rectangle::square(28); - let sq2 = Rectangle::square(35); - - println! ("rect1 可以装下 rect2 吗?{}", rect1.can_hold(&rect2)); - println! ("rect1 可以装下 rect3 吗?{}", rect1.can_hold(&rect3)); - println! ("rect1 可以装下 sq1 吗?{}", rect1.can_hold(&sq1)); - println! ("rect1 可以装下 sq2 吗?{}", rect1.can_hold(&sq2)); -} diff --git a/ref_cycle_demo/Cargo.toml b/ref_cycle_demo/Cargo.toml deleted file mode 100644 index 04d3f91..0000000 --- a/ref_cycle_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "ref_cycle_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/ref_cycle_demo/src/main.rs b/ref_cycle_demo/src/main.rs deleted file mode 100644 index 6fe1657..0000000 --- a/ref_cycle_demo/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; -use crate::List::{Cons, Nil}; - -#[derive(Debug)] -enum List { - Cons(i32, RefCell>), - Nil, -} - -impl List { - fn tail(&self) -> Option<&RefCell>> { - match self { - Cons(_, item) => Some(item), - Nil => None, - } - } -} - -fn main() { - let a = Rc::new(Cons(5, RefCell::new(Rc::new(Nil)))); - - println! ("a 的初始 rc 计数 = {}", Rc::strong_count(&a)); - println! ("a 的下一条目 = {:?}", a.tail()); - - let b = Rc::new(Cons(10, RefCell::new(Rc::clone(&a)))); - - println! ("b 的创建后 a 的 rc 计数 = {}", Rc::strong_count(&a)); - println! ("b 的初始 rc 计数 = {}", Rc::strong_count(&b)); - println! ("b 的下一条目 = {:?}", b.tail()); - - if let Some(link) = a.tail() { - *link.borrow_mut() = Rc::clone(&b); - } - - println! ("在修改 a 之后 b 的 rc 计数 = {}", Rc::strong_count(&b)); - println! ("在修改 a 之后 a 的 rc 计数 = {}", Rc::strong_count(&a)); - - // 取消下面这行注释,就可以看到这里有着循环引用; - // 他将溢出堆栈(it will overflow the stack) - // println! ("a 的下一条目 = {:?}", a.tail()); -} diff --git a/references_demo/Cargo.toml b/references_demo/Cargo.toml deleted file mode 100644 index e30e153..0000000 --- a/references_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "references_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/references_demo/src/main.rs b/references_demo/src/main.rs deleted file mode 100644 index d1a400f..0000000 --- a/references_demo/src/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let mut s = String::from("你好"); - - let r1 = &s; - { - let r2 = &mut s; - r2.push_str(",世界"); - } - - println! ("s = {}, r2 = {}", s, r1); -} diff --git a/refutable_demo/Cargo.toml b/refutable_demo/Cargo.toml deleted file mode 100644 index c3c0cb6..0000000 --- a/refutable_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "refutable_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/refutable_demo/src/main.rs b/refutable_demo/src/main.rs deleted file mode 100644 index 8b3c86b..0000000 --- a/refutable_demo/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - if let x = 5 { - println! ("{}", x); - } -} diff --git a/restaurant/Cargo.toml b/restaurant/Cargo.toml deleted file mode 100644 index 678b365..0000000 --- a/restaurant/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "restaurant" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/restaurant/src/front_of_house.rs b/restaurant/src/front_of_house.rs deleted file mode 100644 index d0a8154..0000000 --- a/restaurant/src/front_of_house.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod hosting; diff --git a/restaurant/src/front_of_house/hosting.rs b/restaurant/src/front_of_house/hosting.rs deleted file mode 100644 index d65f3af..0000000 --- a/restaurant/src/front_of_house/hosting.rs +++ /dev/null @@ -1 +0,0 @@ -pub fn add_to_waitlist() {} diff --git a/restaurant/src/lib.rs b/restaurant/src/lib.rs deleted file mode 100644 index 639b689..0000000 --- a/restaurant/src/lib.rs +++ /dev/null @@ -1,28 +0,0 @@ -mod back_of_house { - pub enum Appetizer { - Soup, - Salad, - } - - pub struct Breakfast { - pub toast: String, - seasonal_fruit: String, - } - - impl Breakfast { - pub fn summer(toast: &str) -> Breakfast { - Breakfast { - toast: String::from(toast), - seasonal_fruit: String::from("peaches"), - } - } - } -} - -mod front_of_house; - -pub use crate::front_of_house::hosting; - -pub fn eat_at_restaurant() { - hosting::add_to_waitlist(); -} diff --git a/returning_closure/Cargo.toml b/returning_closure/Cargo.toml deleted file mode 100644 index 543adda..0000000 --- a/returning_closure/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "returning_closure" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/returning_closure/src/main.rs b/returning_closure/src/main.rs deleted file mode 100644 index 4b6aff7..0000000 --- a/returning_closure/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn returns_closure() -> Box i32> { - Box::new(|x| x + 1) -} - -fn main() { - println!("Hello, world!"); -} diff --git a/rustfix_demo/Cargo.toml b/rustfix_demo/Cargo.toml deleted file mode 100644 index 36f085f..0000000 --- a/rustfix_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rustfix_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/rustfix_demo/src/main.rs b/rustfix_demo/src/main.rs deleted file mode 100644 index e9e9e75..0000000 --- a/rustfix_demo/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn do_something() {} - -fn main() { - for _i in 0..100 { - do_something(); - } -} diff --git a/safe_abstraction/Cargo.toml b/safe_abstraction/Cargo.toml deleted file mode 100644 index 732d446..0000000 --- a/safe_abstraction/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "safe_abstraction" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/safe_abstraction/src/main.rs b/safe_abstraction/src/main.rs deleted file mode 100644 index 0c2f159..0000000 --- a/safe_abstraction/src/main.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(warnings)] - -fn main() { - use std::slice; - - let address = 0x01234usize; - let r = address as *mut i32; - - let values: &[i32] = unsafe { slice::from_raw_parts_mut(r, 10000) }; - - println! ("{:?}", values); -} diff --git a/simple_blog/Cargo.lock b/simple_blog/Cargo.lock deleted file mode 100644 index 5b1eec6..0000000 --- a/simple_blog/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "simple_blog" -version = "0.1.0" diff --git a/simple_blog/Cargo.toml b/simple_blog/Cargo.toml deleted file mode 100644 index 0cae12c..0000000 --- a/simple_blog/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "simple_blog" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/simple_blog/src/lib.rs b/simple_blog/src/lib.rs deleted file mode 100644 index 92deec1..0000000 --- a/simple_blog/src/lib.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -pub struct Post { - state: Option>, - content: String, -} - -impl Post { - pub fn new() -> Post { - Post { - state: Some(Box::new(Draft {})), - content: String::new(), - } - } - - pub fn add_text(&mut self, text: &str) { - self.content.push_str(text); - } - - pub fn content(&self) -> &str { - self.state.as_ref().unwrap().content(self) - } - - pub fn request_review(&mut self) { - if let Some(s) = self.state.take() { - self.state = Some(s.request_review()) - } - } - - pub fn approve(&mut self) { - if let Some(s) = self.state.take() { - self.state = Some(s.approve()) - } - } -} - -trait State { - fn request_review(self: Box) -> Box; - fn approve(self: Box) -> Box; - fn content<'a>(&self, post: &'a Post) -> &'a str { "" } -} - -struct Draft {} - -impl State for Draft { - fn request_review(self: Box) -> Box { - Box::new(PendingReview {}) - } - - fn approve(self: Box) -> Box { - self - } -} - -struct PendingReview {} - -impl State for PendingReview { - fn request_review(self: Box) -> Box { - self - } - - fn approve(self: Box) -> Box { - Box::new(Published {}) - } -} - -struct Published {} - -impl State for Published { - fn request_review(self: Box) -> Box { - self - } - - fn approve(self: Box) -> Box { - self - } - - fn content<'a>(&self, post: &'a Post) -> &'a str { - &post.content - } -} diff --git a/simple_blog/src/main.rs b/simple_blog/src/main.rs deleted file mode 100644 index 3503690..0000000 --- a/simple_blog/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use simple_blog::Post; - -fn main() { - let mut post = Post::new(); - - post.add_text("今天午饭我吃了沙拉。"); - assert_eq! ("", post.content()); - - post.request_review(); - assert_eq! ("", post.content()); - - post.approve(); - assert_eq! ("今天午饭我吃了沙拉。", post.content()); -} diff --git a/simple_gui/Cargo.lock b/simple_gui/Cargo.lock deleted file mode 100644 index ea8b9f4..0000000 --- a/simple_gui/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "simple_gui" -version = "0.1.0" diff --git a/simple_gui/Cargo.toml b/simple_gui/Cargo.toml deleted file mode 100644 index 0de16ee..0000000 --- a/simple_gui/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "simple_gui" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/simple_gui/src/lib.rs b/simple_gui/src/lib.rs deleted file mode 100644 index f38f5b4..0000000 --- a/simple_gui/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -pub trait Draw { - fn draw(&self); -} - -pub struct Screen { - pub components: Vec>, -} - -impl Screen { - pub fn run(&self) { - for component in self.components.iter() { - component.draw(); - } - } -} - -pub struct Button { - pub width: u32, - pub height: u32, - pub label: String, -} - -impl Draw for Button { - fn draw(&self) { - // 具体绘制按钮的代码 - println! ("这是一个大小:{} 像素 x {} 像素,有着 “{}” 标签的按钮;", self.width, self.height, self.label); - } -} diff --git a/simple_gui/src/main.rs b/simple_gui/src/main.rs deleted file mode 100644 index 15e9d0a..0000000 --- a/simple_gui/src/main.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] - -use simple_gui::Draw; - -pub struct SelectBox { - width: u32, - height: u32, - options: Vec, -} - -impl Draw for SelectBox { - fn draw(&self) { - // 具体绘制复选框的代码 - println! ("这是一个大小为:{} 像素 x {} 像素,有着选项:{:?} 的复选框;", self.width, self.height, self.options); - } -} - -use simple_gui::Screen; - -pub fn main() { - let screen = Screen { - components: vec! [Box::new(String::from("你好"))], - }; - - screen.run(); -} diff --git a/sp_demos/Cargo.toml b/sp_demos/Cargo.toml deleted file mode 100644 index e89ee27..0000000 --- a/sp_demos/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "sp_demos" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/sp_demos/src/main.rs b/sp_demos/src/main.rs deleted file mode 100644 index 8f48d41..0000000 --- a/sp_demos/src/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let x = 5; - let y = &mut x; -} diff --git a/static_variable/Cargo.toml b/static_variable/Cargo.toml deleted file mode 100644 index c54583c..0000000 --- a/static_variable/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "static_variable" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/static_variable/src/main.rs b/static_variable/src/main.rs deleted file mode 100644 index 8b82e17..0000000 --- a/static_variable/src/main.rs +++ /dev/null @@ -1,15 +0,0 @@ -static mut COUNTER: u32 = 0; - -fn add_to_count(inc: u32) { - unsafe { - COUNTER += inc; - } -} - -fn main() { - add_to_count(3); - - unsafe { - println! ("COUNTER: {}", COUNTER); - } -} diff --git a/string_demo/Cargo.toml b/string_demo/Cargo.toml deleted file mode 100644 index 1fdddff..0000000 --- a/string_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "string_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/string_demo/src/main.rs b/string_demo/src/main.rs deleted file mode 100644 index 458fe32..0000000 --- a/string_demo/src/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let s = "नमस्ते"; - - for c in s.chars() { - println!("{}", c); - } - - for b in s.bytes() { - println!("{}", b); - } -} diff --git a/structs_demo/Cargo.toml b/structs_demo/Cargo.toml deleted file mode 100644 index fff8dd7..0000000 --- a/structs_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "structs_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/supertrait/Cargo.toml b/supertrait/Cargo.toml deleted file mode 100644 index 3d3c9a8..0000000 --- a/supertrait/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "supertrait" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/supertrait/src/main.rs b/supertrait/src/main.rs deleted file mode 100644 index 07eef4d..0000000 --- a/supertrait/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::fmt; - -trait OutlinePrint: fmt::Display { - fn outline_print(&self) { - let output = self.to_string(); - let len = output.len(); - - println! ("{}", "*".repeat(len + 4)); - println! ("*{}*", " ".repeat(len + 2)); - println! ("* {} *", output); - println! ("*{}*", " ".repeat(len + 2)); - println! ("{}", "*".repeat(len + 4)); - } -} - -struct Point { - x: i32, - y: i32, -} - -impl fmt::Display for Point { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write! (f, "({}, {})", self.x, self.y) - } -} - -impl OutlinePrint for Point {} - -fn main() { - let p = Point { x: -2, y: 3 }; - p.outline_print(); -} diff --git a/traits_demo/src/aggregator/lib.rs b/traits_demo/src/aggregator/lib.rs deleted file mode 100644 index fa644ca..0000000 --- a/traits_demo/src/aggregator/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -pub trait Summary { - fn summarize(&self) -> String; -} - -pub struct NewsArticle { - pub headline: String, - pub location: String, - pub author: String, - pub content: String, -} - -impl Summary for NewsArticle { - fn summarize(&self) -> String { - format!("{}, by {} ({})", self.headline, self.author, self.location) - } -} - -pub struct Tweet { - pub username: String, - pub content: String, - pub reply: bool, - pub retweet: bool, -} - -impl Summary for Tweet { - fn summarize(&self) -> String { - format!("{}: {}", self.username, self.content) - } -} diff --git a/tree_demo/Cargo.toml b/tree_demo/Cargo.toml deleted file mode 100644 index b2f4579..0000000 --- a/tree_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "tree_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/tree_demo/src/main.rs b/tree_demo/src/main.rs deleted file mode 100644 index aacc196..0000000 --- a/tree_demo/src/main.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::cell::RefCell; -use std::rc::{Rc, Weak}; - -#[derive(Debug)] -struct Node { - value: i32, - parent: RefCell>, - children: RefCell>>, -} - -fn main() { - let leaf = Rc::new(Node { - value: 3, - parent: RefCell::new(Weak::new()), - children: RefCell::new(vec! []), - }); - - println! ( - "叶子节点的强引用计数:{},弱引用计数:{}\n", - Rc::strong_count(&leaf), - Rc::weak_count(&leaf), - ); - - { - let branch = Rc::new(Node { - value: 5, - parent: RefCell::new(Weak::new()), - children: RefCell::new(vec! [Rc::clone(&leaf)]), - }); - - *leaf.parent.borrow_mut() = Rc::downgrade(&branch); - - println! ( - "枝干节点的强引用计数:{},弱引用计数:{}\n", - Rc::strong_count(&branch), - Rc::weak_count(&branch), - ); - println! ( - "叶子节点的强引用计数:{},弱引用计数:{}\n", - Rc::strong_count(&leaf), - Rc::weak_count(&leaf), - ); - - } - println! ("叶子节点的父节点 = {:?}\n", leaf.parent.borrow().upgrade()); - println! ( - "叶子节点的强引用计数:{},弱引用计数:{}\n", - Rc::strong_count(&leaf), - Rc::weak_count(&leaf), - ); -} diff --git a/type_aliases/Cargo.toml b/type_aliases/Cargo.toml deleted file mode 100644 index 7d57b28..0000000 --- a/type_aliases/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "type_aliases" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/type_aliases/src/main.rs b/type_aliases/src/main.rs deleted file mode 100644 index 0b5bb45..0000000 --- a/type_aliases/src/main.rs +++ /dev/null @@ -1,20 +0,0 @@ -fn main() { - type Kilometers = i32; - - let x: i32 = 5; - let y: Kilometers = 5; - - assert_eq! (x, y); - - type Thunk = Box; - - let f: Thunk = Box::new(|| println! ("嗨")); - - fn takes_long_type(f: Thunk) { - // --跳过代码-- - } - - fn returns_long_type() -> Thunk { - // --跳过代码-- - } -} diff --git a/unsafe_functions/Cargo.toml b/unsafe_functions/Cargo.toml deleted file mode 100644 index f5d4a5a..0000000 --- a/unsafe_functions/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "unsafe_functions" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/unsafe_functions/src/main.rs b/unsafe_functions/src/main.rs deleted file mode 100644 index 92031a5..0000000 --- a/unsafe_functions/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - unsafe fn dangerous() { - println! ("这是一个不安全函数。"); - } - - dangerous(); -} diff --git a/unsafe_trait/Cargo.toml b/unsafe_trait/Cargo.toml deleted file mode 100644 index 5632c0e..0000000 --- a/unsafe_trait/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "unsafe_trait" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/unsafe_trait/src/main.rs b/unsafe_trait/src/main.rs deleted file mode 100644 index 53c1bb3..0000000 --- a/unsafe_trait/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -unsafe trait Foo { - // 这里是些方法 -} - -unsafe impl Foo for i32 { - // 方法实现在这里 -} - -fn main() {} diff --git a/variables/Cargo.toml b/variables/Cargo.toml deleted file mode 100644 index f1cad76..0000000 --- a/variables/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "variables" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/variables/src/main.rs b/variables/src/main.rs deleted file mode 100644 index 371f983..0000000 --- a/variables/src/main.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::io; -use std::process; - -fn main() { - let a = [1, 2, 3, 4, 5]; - - println! ("请输入一个数组索引。"); - - let mut index = String::new(); - - io::stdin() - .read_line(&mut index) - .expect("读取行失败"); - - let index: usize = match index.trim() - .parse() { - Ok(num) => num, - Err(_) => { - println! ("输入的索引并非数字"); - process::exit(0); - } - }; - - let element = a[index]; - - println! ( - "位于索引 {} 处的元素值为:{}", - index, element); -} diff --git a/vec_demo/Cargo.toml b/vec_demo/Cargo.toml deleted file mode 100644 index f7474b5..0000000 --- a/vec_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "vec_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/vec_demo/src/main.rs b/vec_demo/src/main.rs deleted file mode 100644 index a1607b6..0000000 --- a/vec_demo/src/main.rs +++ /dev/null @@ -1,26 +0,0 @@ -fn main() { - let mut v = vec! [100, 32, 57]; - - for i in &mut v { - *i += 50; - println! ("{}", i); - } - - #[derive(Debug)] - enum SpreadsheetCell { - Int(i32), - Float(f64), - Text(String), - } - - let row = vec! [ - SpreadsheetCell::Int(3), - SpreadsheetCell::Text(String::from("blue")), - SpreadsheetCell::Float(10.12), - ]; - - - println! ("{:#?}", &row[0]) - - // dbg! (v); -} diff --git a/while_let_demo/Cargo.toml b/while_let_demo/Cargo.toml deleted file mode 100644 index c8e909e..0000000 --- a/while_let_demo/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "while_let_demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/while_let_demo/src/main.rs b/while_let_demo/src/main.rs deleted file mode 100644 index 252247c..0000000 --- a/while_let_demo/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let (x, y) = (1, 2, 3); - - // println! ("x: {}, y: {}, z: {}", x, y, z); -}