summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-09-29 13:26:31 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-09-29 13:26:31 +0300
commitd13f336198c40abacff6996f118040ae73dfbb30 (patch)
tree88d96ff022c2d2fec969da3056d49477bda1f59a
downloadrust-book-d13f336198c40abacff6996f118040ae73dfbb30.tar.gz
rust-book-d13f336198c40abacff6996f118040ae73dfbb30.tar.bz2
rust-book-d13f336198c40abacff6996f118040ae73dfbb30.zip
add: hello_world, hello_cargo and guessing_game projects
Diffstat (limited to '')
-rw-r--r--Cargo.lock85
-rw-r--r--Cargo.toml7
-rw-r--r--notes/0001.org3
-rw-r--r--src/guessing_game/Cargo.toml7
-rw-r--r--src/guessing_game/src/main.rs38
-rw-r--r--src/hello_cargo/Cargo.toml6
-rw-r--r--src/hello_cargo/src/main.rs3
-rw-r--r--src/hello_world/Cargo.toml6
-rw-r--r--src/hello_world/src/main.rs3
9 files changed, 158 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..12e777b
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,85 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "cfg-if"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
+
+[[package]]
+name = "chacha20"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
+dependencies = [
+ "cfg-if",
+ "cpufeatures",
+ "rand_core",
+]
+
+[[package]]
+name = "cpufeatures"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "r-efi",
+ "rand_core",
+]
+
+[[package]]
+name = "guessing_game"
+version = "0.1.0"
+dependencies = [
+ "rand",
+]
+
+[[package]]
+name = "hello_cargo"
+version = "0.1.0"
+
+[[package]]
+name = "hello_world"
+version = "0.1.0"
+
+[[package]]
+name = "libc"
+version = "0.2.189"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
+
+[[package]]
+name = "r-efi"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
+
+[[package]]
+name = "rand"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
+dependencies = [
+ "chacha20",
+ "getrandom",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..46d9f2e
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,7 @@
+[workspace]
+members = [
+ "src/hello_world",
+ "src/hello_cargo",
+ "src/guessing_game",
+]
+resolver = "2"
diff --git a/notes/0001.org b/notes/0001.org
new file mode 100644
index 0000000..d578607
--- /dev/null
+++ b/notes/0001.org
@@ -0,0 +1,3 @@
+* Ссылки
+- [[https://doc.rust-lang.org/stable/book/title-page.html][Оригинал rust-book]]
+- [[https://doc.rust-lang.ru/book/title-page.html][Русский перевод rust-book]]
diff --git a/src/guessing_game/Cargo.toml b/src/guessing_game/Cargo.toml
new file mode 100644
index 0000000..15924f9
--- /dev/null
+++ b/src/guessing_game/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "guessing_game"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+rand = "0.10.1" \ No newline at end of file
diff --git a/src/guessing_game/src/main.rs b/src/guessing_game/src/main.rs
new file mode 100644
index 0000000..029eb36
--- /dev/null
+++ b/src/guessing_game/src/main.rs
@@ -0,0 +1,38 @@
+use std::io;
+use std::cmp::Ordering;
+
+use rand::prelude::*;
+
+fn main() {
+ println!("Guess the number!");
+
+ let secret_number = rand::rng().random_range(1..=100);
+
+ //println!("The secret number is: {secret_number}");
+
+ loop {
+ println!("Please input your guess.");
+
+ let mut guess = String::new();
+
+ io::stdin()
+ .read_line(&mut guess)
+ .expect("Failed to read line");
+
+ let guess: u32 = match guess.trim().parse() {
+ Ok(num) => num,
+ Err(_) => continue,
+ };
+
+ println!("You guessed: {guess}");
+
+ match guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
+ println!("You win!");
+ break;
+ }
+ }
+ }
+}
diff --git a/src/hello_cargo/Cargo.toml b/src/hello_cargo/Cargo.toml
new file mode 100644
index 0000000..f43e5f8
--- /dev/null
+++ b/src/hello_cargo/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello_cargo"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/hello_cargo/src/main.rs b/src/hello_cargo/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/hello_cargo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/hello_world/Cargo.toml b/src/hello_world/Cargo.toml
new file mode 100644
index 0000000..4f0a461
--- /dev/null
+++ b/src/hello_world/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "hello_world"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/hello_world/src/main.rs b/src/hello_world/src/main.rs
new file mode 100644
index 0000000..e7a11a9
--- /dev/null
+++ b/src/hello_world/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}