summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-10-03 12:24:34 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-10-03 12:24:34 +0300
commit42ac98a58c2d37dc05bcfd32dbc0dff6f231657f (patch)
treeb1189a29cf8df2398c086ee072c33faa7657239c
parentf6cbf2bf76e77c8f64312f573f46cdc7bd434acd (diff)
downloadrust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.tar.gz
rust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.tar.bz2
rust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.zip
add: rectangles
Diffstat (limited to '')
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml1
-rw-r--r--src/rectangles/Cargo.toml6
-rw-r--r--src/rectangles/src/main.rs24
4 files changed, 35 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b661321..264ca5d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -109,6 +109,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
+name = "rectangles"
+version = "0.1.0"
+
+[[package]]
name = "shadowing"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index 6548d00..d8bba20 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,5 +11,6 @@ members = [
"src/fahr2cel",
"src/fibonacci",
"src/christmas_song",
+ "src/rectangles",
]
resolver = "2"
diff --git a/src/rectangles/Cargo.toml b/src/rectangles/Cargo.toml
new file mode 100644
index 0000000..bd5e247
--- /dev/null
+++ b/src/rectangles/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "rectangles"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/rectangles/src/main.rs b/src/rectangles/src/main.rs
new file mode 100644
index 0000000..fec8596
--- /dev/null
+++ b/src/rectangles/src/main.rs
@@ -0,0 +1,24 @@
+#[derive(Debug)]
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+fn main() {
+ let scale = 2;
+ let rect1 = Rectangle {
+ width: dbg!(30 * scale),
+ height: 50,
+ };
+
+ dbg!(&rect1);
+
+ println!(
+ "The area of the rectangle is {} square pixels.",
+ area(&rect1)
+ );
+}
+
+fn area(rectangle: &Rectangle) -> u32 {
+ rectangle.width * rectangle.height
+}