summaryrefslogtreecommitdiffstats
path: root/src/rectangles
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 /src/rectangles
parentf6cbf2bf76e77c8f64312f573f46cdc7bd434acd (diff)
downloadrust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.tar.gz
rust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.tar.bz2
rust-book-42ac98a58c2d37dc05bcfd32dbc0dff6f231657f.zip
add: rectangles
Diffstat (limited to '')
-rw-r--r--src/rectangles/Cargo.toml6
-rw-r--r--src/rectangles/src/main.rs24
2 files changed, 30 insertions, 0 deletions
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
+}