From 80cc58aebe53e06c24422110ac31cb7a927800dd Mon Sep 17 00:00:00 2001 From: sunface Date: Mon, 14 Mar 2022 21:14:52 +0800 Subject: [PATCH] add practice projects --- practices/hello-package/.gitignore | 1 + practices/hello-package/Cargo.lock | 7 +++++++ practices/hello-package/Cargo.toml | 8 ++++++++ practices/hello-package/Readme.md | 20 +++++++++++++++++++ practices/hello-package/src/back_of_house.rs | 7 +++++++ .../src/front_of_house/hosting.rs | 6 ++++++ .../hello-package/src/front_of_house/mod.rs | 2 ++ .../src/front_of_house/serving.rs | 9 +++++++++ practices/hello-package/src/lib.rs | 12 +++++++++++ practices/hello-package/src/main.rs | 4 ++++ 10 files changed, 76 insertions(+) create mode 100644 practices/hello-package/.gitignore create mode 100644 practices/hello-package/Cargo.lock create mode 100644 practices/hello-package/Cargo.toml create mode 100644 practices/hello-package/Readme.md create mode 100644 practices/hello-package/src/back_of_house.rs create mode 100644 practices/hello-package/src/front_of_house/hosting.rs create mode 100644 practices/hello-package/src/front_of_house/mod.rs create mode 100644 practices/hello-package/src/front_of_house/serving.rs create mode 100644 practices/hello-package/src/lib.rs create mode 100644 practices/hello-package/src/main.rs diff --git a/practices/hello-package/.gitignore b/practices/hello-package/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/practices/hello-package/.gitignore @@ -0,0 +1 @@ +/target diff --git a/practices/hello-package/Cargo.lock b/practices/hello-package/Cargo.lock new file mode 100644 index 0000000..dbd6e7c --- /dev/null +++ b/practices/hello-package/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello-package" +version = "0.1.0" diff --git a/practices/hello-package/Cargo.toml b/practices/hello-package/Cargo.toml new file mode 100644 index 0000000..0630563 --- /dev/null +++ b/practices/hello-package/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "hello-package" +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/practices/hello-package/Readme.md b/practices/hello-package/Readme.md new file mode 100644 index 0000000..ce7a586 --- /dev/null +++ b/practices/hello-package/Readme.md @@ -0,0 +1,20 @@ +## Hello Package +A practice project used in [Crate and Module](https://practice.rs/crate-module/crate.html) chapter. + +This project will guide us to create a package with a binary crate and several library crates in it. + +The project structure is as below: +```shell +. +├── Cargo.lock +├── Cargo.toml +├── Readme.md +├── src +│   ├── back_of_house.rs +│   ├── front_of_house +│   │   ├── hosting.rs +│   │   ├── mod.rs +│   │   └── serving.rs +│   ├── lib.rs +│   └── main.rs +``` \ No newline at end of file diff --git a/practices/hello-package/src/back_of_house.rs b/practices/hello-package/src/back_of_house.rs new file mode 100644 index 0000000..a996ea9 --- /dev/null +++ b/practices/hello-package/src/back_of_house.rs @@ -0,0 +1,7 @@ +use crate::front_of_house; +pub fn fix_incorrect_order() { + cook_order(); + front_of_house::serving::serve_order(); +} + +pub fn cook_order() {} \ No newline at end of file diff --git a/practices/hello-package/src/front_of_house/hosting.rs b/practices/hello-package/src/front_of_house/hosting.rs new file mode 100644 index 0000000..f047f83 --- /dev/null +++ b/practices/hello-package/src/front_of_house/hosting.rs @@ -0,0 +1,6 @@ +pub fn add_to_waitlist() {} + +pub fn seat_at_table() -> String { + String::from("sit down please") +} + diff --git a/practices/hello-package/src/front_of_house/mod.rs b/practices/hello-package/src/front_of_house/mod.rs new file mode 100644 index 0000000..9a500d1 --- /dev/null +++ b/practices/hello-package/src/front_of_house/mod.rs @@ -0,0 +1,2 @@ +pub mod hosting; +pub mod serving; \ No newline at end of file diff --git a/practices/hello-package/src/front_of_house/serving.rs b/practices/hello-package/src/front_of_house/serving.rs new file mode 100644 index 0000000..129c8fa --- /dev/null +++ b/practices/hello-package/src/front_of_house/serving.rs @@ -0,0 +1,9 @@ +pub fn take_order() {} + +pub fn serve_order() {} + +pub fn take_payment() {} + +// Maybe you don't want the guest hearing the your complaining about them +// So just make it private +fn complain() {} \ No newline at end of file diff --git a/practices/hello-package/src/lib.rs b/practices/hello-package/src/lib.rs new file mode 100644 index 0000000..00a6c73 --- /dev/null +++ b/practices/hello-package/src/lib.rs @@ -0,0 +1,12 @@ +mod front_of_house; +mod back_of_house; + +pub use crate::front_of_house::hosting; + +pub fn eat_at_restaurant() -> String { + front_of_house::hosting::add_to_waitlist(); + + back_of_house::cook_order(); + + String::from("yummy yummy!") +} diff --git a/practices/hello-package/src/main.rs b/practices/hello-package/src/main.rs new file mode 100644 index 0000000..061775f --- /dev/null +++ b/practices/hello-package/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + assert_eq!(hello_package::hosting::seat_at_table(), "sit down please"); + assert_eq!(hello_package::eat_at_restaurant(),"yummy yummy!"); +}