Skip to content

Commit 90a5ebe

Browse files
rust basic [9]
1 parent ccb5238 commit 90a5ebe

File tree

6 files changed

+162
-1
lines changed

6 files changed

+162
-1
lines changed

Cargo.lock

+133
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
rand = "0.8.4"

src/_22_enum.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ fn print_status(status: YoStatus) {
1414

1515
pub fn main() {
1616
let current_status = YoStatus::Online;
17-
print_status(current_status); // Expected: "User is online"
17+
print_status(current_status); // Expected: "User is Online"
18+
let current_status2 = YoStatus::Offline;
19+
print_status(current_status2); // Expected: "User is Offline"
20+
let current_status3 = YoStatus::Busy;
21+
print_status(current_status3); // Expected: "User is Busy"
1822
}
1923
// Real Scenario: Represent states or configurations, such as a network status.

src/_25_yo_module.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mod yo_utils {
2+
pub fn greet(name: &str) {
3+
println!("Yo, {}!", name); // Gree the user
4+
}
5+
}
6+
7+
pub fn main() {
8+
yo_utils::greet("Rustacean"); // Expected: "Yo, Rustacean!"
9+
}
10+
11+
// Real Scenario: Structure large projects for maintainability.

src/_26_yo_crate.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use rand::Rng;
2+
3+
pub fn main() {
4+
let random_number = rand::thread_rng().gen_range(1..101);
5+
println!("Yo, random number: {}", random_number);
6+
}
7+
8+
// Real Scenario: Leverage community-provided libraries for common tasks.

src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ mod _21_yo_method;
1515
mod _22_enum;
1616
mod _23_yo_pattern_matching;
1717
mod _24_yo_type_alias;
18+
mod _25_yo_module;
19+
mod _26_yo_crate;
1820
mod _2_data_types;
1921
mod _3_numbers;
2022
mod _4_operators_comparison;
@@ -67,4 +69,6 @@ fn main() {
6769
_22_enum::main();
6870
_23_yo_pattern_matching::main();
6971
_24_yo_type_alias::main();
72+
_25_yo_module::main();
73+
_26_yo_crate::main();
7074
}

0 commit comments

Comments
 (0)