add practice projects
This commit is contained in:
parent
df2e2fe02c
commit
80cc58aebe
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -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"
|
|
@ -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]
|
|
@ -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
|
||||||
|
```
|
|
@ -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() {}
|
|
@ -0,0 +1,6 @@
|
||||||
|
pub fn add_to_waitlist() {}
|
||||||
|
|
||||||
|
pub fn seat_at_table() -> String {
|
||||||
|
String::from("sit down please")
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod hosting;
|
||||||
|
pub mod serving;
|
|
@ -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() {}
|
|
@ -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!")
|
||||||
|
}
|
|
@ -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!");
|
||||||
|
}
|
Loading…
Reference in New Issue