commit 1170ebe04d15bf03afe5d3ac88ac83c0afee30cc Author: Amoelle Date: Tue Jul 1 10:51:25 2025 +0300 Flatten nested Rust projects into monorepo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd47585 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +**/target/ +**/*.o +**/*.d +**/*.exe +**/*.log +**/*.rlib +**/*.dylib +**/*.so +**/.DS_Store +**/.vscode/ +**/.idea/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..18a11d3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +members = [ + "branches", + "data_types", + "functions", + "guessing_game", + "hello_cargo", + "loops", + "ownership", + "variables", +] diff --git a/branches/Cargo.lock b/branches/Cargo.lock new file mode 100644 index 0000000..c5d0014 --- /dev/null +++ b/branches/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "branches" +version = "0.1.0" diff --git a/branches/Cargo.toml b/branches/Cargo.toml new file mode 100644 index 0000000..b12fd97 --- /dev/null +++ b/branches/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "branches" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/branches/src/main.rs b/branches/src/main.rs new file mode 100644 index 0000000..ee286c8 --- /dev/null +++ b/branches/src/main.rs @@ -0,0 +1,20 @@ +fn main() { + let condition = true; + let result = if condition { 5 } else { 6 }; + // let result = if condition { 5 } else { 'six' }; + // will throw an error, should be the same type + + println!("The result is {result}"); + + let number = 6; + + if number % 4 == 0 { + println!("number is divisible by 4"); + } else if number % 3 == 0 { + println!("number is divisible by 3"); + } else if number % 2 == 0 { + println!("number is divisible by 2"); + } else { + println!("number is not divisible by 4, 3, or 2"); + } +} diff --git a/cleanup.sh b/cleanup.sh new file mode 100755 index 0000000..3b1494b --- /dev/null +++ b/cleanup.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# This script assumes you're in the monorepo root directory. +# It will: +# - Remove nested .git folders +# - Remove subproject .gitignore files (if present) +# - Optionally create or update the workspace Cargo.toml +# - Add the projects to your root Git repo + +set -e + +echo "🔧 Flattening nested Rust projects into a monorepo..." + +# Gather all Rust subprojects +projects=() +for dir in */Cargo.toml; do + project=$(dirname "$dir") + projects+=("$project") + + # Remove nested Git repo + if [ -d "$project/.git" ]; then + echo "❌ Removing nested Git repo in $project" + rm -rf "$project/.git" + fi + + # Optionally remove local .gitignore (you can comment this out if needed) + if [ -f "$project/.gitignore" ]; then + echo "❌ Removing $project/.gitignore" + rm -f "$project/.gitignore" + fi +done + +# Create .gitignore in root if missing +if [ ! -f .gitignore ]; then + echo "📄 Creating root .gitignore" + cat > .gitignore < Cargo.toml + echo "members = [" >> Cargo.toml + for project in "${projects[@]}"; do + echo " \"$project\"," >> Cargo.toml + done + echo "]" >> Cargo.toml +else + echo "⚠️ Cargo.toml already exists at root. You may need to manually add workspace members." +fi + +# Init root Git repo if not already +if [ ! -d .git ]; then + echo "🔁 Initializing new root Git repo" + git init +fi + +# Add and commit +git add . +git commit -m "Flatten nested Rust projects into monorepo" + +echo "✅ Done! Monorepo is clean and ready." + diff --git a/data_types/Cargo.lock b/data_types/Cargo.lock new file mode 100644 index 0000000..db98cb0 --- /dev/null +++ b/data_types/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "data_types" +version = "0.1.0" diff --git a/data_types/Cargo.toml b/data_types/Cargo.toml new file mode 100644 index 0000000..5b2fddb --- /dev/null +++ b/data_types/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "data_types" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/data_types/src/main.rs b/data_types/src/main.rs new file mode 100644 index 0000000..b84a09e --- /dev/null +++ b/data_types/src/main.rs @@ -0,0 +1,35 @@ +use std::io; + +fn main() { + let tup: (u32, f64, i8) = (500, 420.69, 1); // different types + let fiveh = tup.0; + let fourtw = tup.1; + let one = tup.2; + let (x, y, z) = tup; + + let nums: [i32; 5] = [1, 2, 3, 4, 5]; // only one data type + let a = [3; 5]; // same as + // let a = [3, 3, 3, 3, 3]; + + let first = nums[0]; + let second = nums[1]; + + + let a = [1, 2, 3, 4, 5]; + + println!("Type an index"); + + let mut index = String::new(); + io::stdin() + .read_line(&mut index) + .expect("Failed to read line"); + + let index: usize = index + .trim() + .parse() + .expect("Index wasn't a valid numver"); + + let element = a[index]; + + println!("The element for the index {index} is: {element}"); +} diff --git a/functions/Cargo.lock b/functions/Cargo.lock new file mode 100644 index 0000000..8a72924 --- /dev/null +++ b/functions/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "functions" +version = "0.1.0" diff --git a/functions/Cargo.toml b/functions/Cargo.toml new file mode 100644 index 0000000..9c392ab --- /dev/null +++ b/functions/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "functions" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/functions/src/main.rs b/functions/src/main.rs new file mode 100644 index 0000000..0ca3b0d --- /dev/null +++ b/functions/src/main.rs @@ -0,0 +1,32 @@ +fn main() { + another(10); + measure(10, 'm'); + + let a = numba(); + println!("Value of a: {a}"); + + let x = { + let y = 3; + y + 2 // returns a Value + // but: + // let x = { + // let y = 3; + // y + 2; + // }; + // just a statement, doesnt return any value + }; // This is an expression + + println!("Value of x: {x}"); +} + +fn another(x: u32) { + println!("{x}"); +} + +fn measure(height: i32, unit: char) { + println!("Measuring... {height}{unit}."); +} + +fn numba() -> i32 { + 69 +} diff --git a/guessing_game/Cargo.lock b/guessing_game/Cargo.lock new file mode 100644 index 0000000..22eaac5 --- /dev/null +++ b/guessing_game/Cargo.lock @@ -0,0 +1,133 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "guessing_game" +version = "0.1.0" +dependencies = [ + "rand", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/guessing_game/Cargo.toml b/guessing_game/Cargo.toml new file mode 100644 index 0000000..9f9c4ac --- /dev/null +++ b/guessing_game/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "guessing_game" +version = "0.1.0" +edition = "2024" + +[dependencies] +rand = "0.8.5" diff --git a/guessing_game/src/main.rs b/guessing_game/src/main.rs new file mode 100644 index 0000000..4e3b187 --- /dev/null +++ b/guessing_game/src/main.rs @@ -0,0 +1,50 @@ +// use std::cmp::Ordering; +use std::io; + +use rand::Rng; + +fn main() { + println!("Guess a numba"); + + let secret_number = rand::thread_rng().gen_range(1..=100); + // println!("The secret numba is: {secret_number}"); + + let mut number_of_guesses = 0; + + loop { + println!("Do your input"); + + let mut guess = String::new(); + + io::stdin().read_line(&mut guess).expect("Nothing here"); + + let guess: u32 = match guess.trim().parse() { + Ok(num) => num, + Err(_) => continue, + }; + + println!("Your guess: {guess}"); + + if guess > secret_number { + println!("Secret number is smaller!"); + } else if guess < secret_number { + println!("Secret number is bigger!"); + } else { + println!("You got me! Secret number is: {secret_number}"); + break; + } + + number_of_guesses += 1; + + // match guess.cmp(&secret_number) { + // Ordering::Less => println!("Bigger!"), + // Ordering::Greater => println!("Smaller!"), + // Ordering::Equal => { + // println!("Got me :("); + // break; + // } + // } + } + + println!("\nIt took you {number_of_guesses} times to guess correctly!"); +} diff --git a/hello_cargo/Cargo.lock b/hello_cargo/Cargo.lock new file mode 100644 index 0000000..feebdd1 --- /dev/null +++ b/hello_cargo/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello_cargo" +version = "0.1.0" diff --git a/hello_cargo/Cargo.toml b/hello_cargo/Cargo.toml new file mode 100644 index 0000000..f43e5f8 --- /dev/null +++ b/hello_cargo/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello_cargo" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/hello_cargo/src/main.rs b/hello_cargo/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/hello_cargo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/hello_world/main b/hello_world/main new file mode 100755 index 0000000..fec141f Binary files /dev/null and b/hello_world/main differ diff --git a/hello_world/main.rs b/hello_world/main.rs new file mode 100644 index 0000000..47ad8c6 --- /dev/null +++ b/hello_world/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello World!"); +} diff --git a/loops/Cargo.lock b/loops/Cargo.lock new file mode 100644 index 0000000..7261438 --- /dev/null +++ b/loops/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "loops" +version = "0.1.0" diff --git a/loops/Cargo.toml b/loops/Cargo.toml new file mode 100644 index 0000000..a046a76 --- /dev/null +++ b/loops/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "loops" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/loops/src/main.rs b/loops/src/main.rs new file mode 100644 index 0000000..c2308a1 --- /dev/null +++ b/loops/src/main.rs @@ -0,0 +1,65 @@ +fn main() { + + let mut counter = 0; + + let result = loop { + counter += 1; + + if counter == 10 { + break counter * 6; + } + }; + + println!("Result is: {result}"); + + let mut count = 0; + 'inner_loop: loop { + println!("Counter: {count}"); + let mut remaining = 10; + + loop { + println!("Remain: {remaining}"); + if remaining == 9 { + break; + } + if count == 2 { + break 'inner_loop; + } + remaining -= 1; + } + + count += 1; + } + + println!("End of counter: {count}"); + + + let mut number = 3; + + while number != 0 { + println!("{number}!"); + + number -= 1; + } + + println!("LIFTOFF!!!"); + + + let a = [10, 20, 30, 40, 50]; + let mut index = 0; + + while index < 5 { + println!("the value is: {}", a[index]); + + index += 1; + } + + for element in a { + println!("the value is: {element}"); + } // this is better and safer usecase for listing elements of an array + + for number in (1..4).rev() { + println!("{number}!"); + } + println!("LIFTOFF!!!"); +} diff --git a/ownership/Cargo.lock b/ownership/Cargo.lock new file mode 100644 index 0000000..8c5b86e --- /dev/null +++ b/ownership/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ownership" +version = "0.1.0" diff --git a/ownership/Cargo.toml b/ownership/Cargo.toml new file mode 100644 index 0000000..e884752 --- /dev/null +++ b/ownership/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ownership" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/ownership/src/main.rs b/ownership/src/main.rs new file mode 100644 index 0000000..5a2450d --- /dev/null +++ b/ownership/src/main.rs @@ -0,0 +1,5 @@ +fn main() { + let mut s = String::from("Hello"); + s.push_str(", World!"); + println!("{s}"); +} diff --git a/variables/Cargo.lock b/variables/Cargo.lock new file mode 100644 index 0000000..f26e54f --- /dev/null +++ b/variables/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "variables" +version = "0.1.0" diff --git a/variables/Cargo.toml b/variables/Cargo.toml new file mode 100644 index 0000000..c093eb6 --- /dev/null +++ b/variables/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "variables" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/variables/src/main.rs b/variables/src/main.rs new file mode 100644 index 0000000..045e2b1 --- /dev/null +++ b/variables/src/main.rs @@ -0,0 +1,16 @@ +fn main() { + let x = 10; + + let x = x * 5; + + { + let x = x / 2; + println!("x in the inner scope: {x}"); + } + + println!("x in the outer scope: {x}"); + + // let mut space = " "; + // space = space.len(); + // println!("spaces: {space}"); +}