-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
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); | ||
} | ||
} |
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); | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
🧰 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)