add practice projects

This commit is contained in:
sunface 2022-03-14 21:14:52 +08:00
parent df2e2fe02c
commit 80cc58aebe
10 changed files with 76 additions and 0 deletions

1
practices/hello-package/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
practices/hello-package/Cargo.lock generated Normal file
View File

@ -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"

View File

@ -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]

View File

@ -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
```

View File

@ -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() {}

View File

@ -0,0 +1,6 @@
pub fn add_to_waitlist() {}
pub fn seat_at_table() -> String {
String::from("sit down please")
}

View File

@ -0,0 +1,2 @@
pub mod hosting;
pub mod serving;

View File

@ -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() {}

View File

@ -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!")
}

View File

@ -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!");
}