From 71529b46c6efa277952b9c191772b7eb7df5816c Mon Sep 17 00:00:00 2001 From: Shyam Kumar Date: Sat, 21 Dec 2024 15:47:13 +0530 Subject: [PATCH 1/2] Add Chapter 2: Exploring Rust Basics --- book-compendium/chapter-2/README.md | 7 ++ book-compendium/chapter-2/control_flow.rs | 13 +++ book-compendium/chapter-2/ownership.rs | 12 +++ book-compendium/chapter-2/varibles.rs | 9 ++ package-lock.json | 120 ++++++++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 book-compendium/chapter-2/README.md create mode 100644 book-compendium/chapter-2/control_flow.rs create mode 100644 book-compendium/chapter-2/ownership.rs create mode 100644 book-compendium/chapter-2/varibles.rs diff --git a/book-compendium/chapter-2/README.md b/book-compendium/chapter-2/README.md new file mode 100644 index 0000000..0924928 --- /dev/null +++ b/book-compendium/chapter-2/README.md @@ -0,0 +1,7 @@ +# Chapter 2: Exploring Rust Basics + +This chapter introduces key Rust concepts with simple examples. + +1. **`variables.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. diff --git a/book-compendium/chapter-2/control_flow.rs b/book-compendium/chapter-2/control_flow.rs new file mode 100644 index 0000000..7d52940 --- /dev/null +++ b/book-compendium/chapter-2/control_flow.rs @@ -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); + } +} diff --git a/book-compendium/chapter-2/ownership.rs b/book-compendium/chapter-2/ownership.rs new file mode 100644 index 0000000..3f177cb --- /dev/null +++ b/book-compendium/chapter-2/ownership.rs @@ -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); +} diff --git a/book-compendium/chapter-2/varibles.rs b/book-compendium/chapter-2/varibles.rs new file mode 100644 index 0000000..1d287cc --- /dev/null +++ b/book-compendium/chapter-2/varibles.rs @@ -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); +} diff --git a/package-lock.json b/package-lock.json index bc9b2f0..473df31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5082,6 +5082,126 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/@next/swc-darwin-arm64": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.4.tgz", + "integrity": "sha512-AH3mO4JlFUqsYcwFUHb1wAKlebHU/Hv2u2kb1pAuRanDZ7pD/A/KPD98RHZmwsJpdHQwfEc/06mgpSzwrJYnNg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.4.tgz", + "integrity": "sha512-QVadW73sWIO6E2VroyUjuAxhWLZWEpiFqHdZdoQ/AMpN9YWGuHV8t2rChr0ahy+irKX5mlDU7OY68k3n4tAZTg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.4.tgz", + "integrity": "sha512-KT6GUrb3oyCfcfJ+WliXuJnD6pCpZiosx2X3k66HLR+DMoilRb76LpWPGb4tZprawTtcnyrv75ElD6VncVamUQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.4.tgz", + "integrity": "sha512-Alv8/XGSs/ytwQcbCHwze1HmiIkIVhDHYLjczSVrf0Wi2MvKn/blt7+S6FJitj3yTlMwMxII1gIJ9WepI4aZ/A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.4.tgz", + "integrity": "sha512-ze0ShQDBPCqxLImzw4sCdfnB3lRmN3qGMB2GWDRlq5Wqy4G36pxtNOo2usu/Nm9+V2Rh/QQnrRc2l94kYFXO6Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.4.tgz", + "integrity": "sha512-8dwC0UJoc6fC7PX70csdaznVMNr16hQrTDAMPvLPloazlcaWfdPogq+UpZX6Drqb1OBlwowz8iG7WR0Tzk/diQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.4.tgz", + "integrity": "sha512-jxyg67NbEWkDyvM+O8UDbPAyYRZqGLQDTPwvrBBeOSyVWW/jFQkQKQ70JDqDSYg1ZDdl+E3nkbFbq8xM8E9x8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.4", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.4.tgz", + "integrity": "sha512-twrmN753hjXRdcrZmZttb/m5xaCBFa48Dt3FbeEItpJArxriYDunWxJn+QFXdJ3hPkm4u7CKxncVvnmgQMY1ag==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } From 060822150c9d7be5ec5a3fa2b2d4a0a3420b5bbb Mon Sep 17 00:00:00 2001 From: Shyam Kumar Date: Sat, 21 Dec 2024 16:29:46 +0530 Subject: [PATCH 2/2] Changed typo --- book-compendium/chapter-2/README.md | 2 +- book-compendium/chapter-2/{varibles.rs => varible.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename book-compendium/chapter-2/{varibles.rs => varible.rs} (100%) diff --git a/book-compendium/chapter-2/README.md b/book-compendium/chapter-2/README.md index 0924928..00b8d52 100644 --- a/book-compendium/chapter-2/README.md +++ b/book-compendium/chapter-2/README.md @@ -2,6 +2,6 @@ This chapter introduces key Rust concepts with simple examples. -1. **`variables.rs`**: Demonstrates variables, immutability, and mutability in Rust. +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. diff --git a/book-compendium/chapter-2/varibles.rs b/book-compendium/chapter-2/varible.rs similarity index 100% rename from book-compendium/chapter-2/varibles.rs rename to book-compendium/chapter-2/varible.rs