Migration from GitHub

This commit is contained in:
rarmknecht
2025-12-19 23:39:55 -06:00
commit 90a79b7923
25 changed files with 3017 additions and 0 deletions

5
chapter_05/rectangles/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "rectangles"
version = "0.1.0"

View File

@@ -0,0 +1,9 @@
[package]
name = "rectangles"
version = "0.1.0"
authors = ["rarmknecht <rarmknecht@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,45 @@
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
fn can_hold(&self, other: &Rectangle) -> bool {
self.width > other.width && self.height > other.height
}
fn square(size: u32) -> Rectangle {
Rectangle {
width: size,
height: size,
}
}
}
fn main() {
let rect1 = Rectangle {
width: 30,
height: 50,
};
println!(
"The area of the rectangle is {} square pixels.",
rect1.area()
);
println!(
"This rectangle fits inside: {}",
rect1.can_hold(&Rectangle {width: 20, height: 30,})
);
println!(
"This is a square! {:?}",
Rectangle::square(32)
);
}

View File

@@ -0,0 +1,16 @@
fn main() {
let widthl = 30;
let heightl = 50;
println!(
"The area of the rectangle is {} square pixels",
area(widthl, heightl)
);
}
fn area(width: u32, height: u32) -> u32 {
width * height
}

View File

@@ -0,0 +1,20 @@
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle {
width: 30,
height: 50,
};
println!(
"The area of the rectangle is {} square pixels.",
area(&rect1)
);
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}