Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chapter 2: Exploring Rust Basics #188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions book-compendium/chapter-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Chapter 2: Exploring Rust Basics

This chapter introduces key Rust concepts with simple examples.

1. **`variable.rs`**: Demonstrates variables, immutability, and mutability in Rust.
2. **`control_flow.rs`**: Explains basic control flow constructs like `if-else` and loops.
3. **`ownership.rs`**: Introduces Rust's ownership model and function interactions.
Comment on lines +5 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Update filename reference and add more details about each example

The README references "variable.rs" but the actual file is "varible.rs" (which should be fixed). Also, consider adding more details about what each example demonstrates.

-1. **`variable.rs`**: Demonstrates variables, immutability, and mutability in Rust.
-2. **`control_flow.rs`**: Explains basic control flow constructs like `if-else` and loops.
-3. **`ownership.rs`**: Introduces Rust's ownership model and function interactions.
+1. **`variable.rs`**: Demonstrates variables in Rust, covering:
+   - Immutable variables (default in Rust)
+   - Mutable variables using the `mut` keyword
+   - Type inference and explicit type annotations
+
+2. **`control_flow.rs`**: Explains basic control flow constructs including:
+   - Conditional statements (`if`-`else`)
+   - Different types of loops
+   - Early return and break statements
+
+3. **`ownership.rs`**: Introduces Rust's unique ownership system:
+   - Understanding ownership rules
+   - Move semantics
+   - Function parameter ownership

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: Loose punctuation mark.
Context: ...h simple examples. 1. variable.rs: Demonstrates variables, immutability, a...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~6-~6: Loose punctuation mark.
Context: ...bility in Rust. 2. control_flow.rs: Explains basic control flow constructs ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~7-~7: Loose punctuation mark.
Context: ...f-else and loops. 3. **ownership.rs`**: Introduces Rust's ownership model and f...

(UNLIKELY_OPENING_PUNCTUATION)

13 changes: 13 additions & 0 deletions book-compendium/chapter-2/control_flow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
let number = 7;

if number < 10 {
println!("Number is less than 10");
} else {
println!("Number is greater than or equal to 10");
}

for i in 0..5 {
println!("Value of i: {}", i);
}
}
12 changes: 12 additions & 0 deletions book-compendium/chapter-2/ownership.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main() {
let s = String::from("Hello, Ownership!");

take_ownership(s);

// Uncommenting the line below will cause an error, as `s` is no longer valid.
// println!("{}", s);
}

fn take_ownership(some_string: String) {
println!("{}", some_string);
}
9 changes: 9 additions & 0 deletions book-compendium/chapter-2/varible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let x = 5; // Immutable variable
println!("x = {}", x);

let mut y = 10; // Mutable variable
println!("y before mutation = {}", y);
y = 15;
println!("y after mutation = {}", y);
}
Comment on lines +1 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the filename typo: "varible.rs" → "variable.rs"

The filename contains a typo which should be corrected to maintain consistency with the README and ensure clarity for learners.

120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.