summaryrefslogtreecommitdiff
path: root/structs/src/main.rs
diff options
context:
space:
mode:
authorAdam Carpenter <adam.carpenter@adp.com>2019-02-11 16:59:01 -0500
committerAdam Carpenter <adam.carpenter@adp.com>2019-02-11 16:59:01 -0500
commitef1bf4921ee4127d461eec03a14c9070d193345c (patch)
treeab9f4ed73fcf97656743c959ce8c9adbe2ce9924 /structs/src/main.rs
downloadlearning-rust-ef1bf4921ee4127d461eec03a14c9070d193345c.tar.xz
learning-rust-ef1bf4921ee4127d461eec03a14c9070d193345c.zip
Init.
Diffstat (limited to 'structs/src/main.rs')
-rwxr-xr-xstructs/src/main.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/structs/src/main.rs b/structs/src/main.rs
new file mode 100755
index 0000000..cf93866
--- /dev/null
+++ b/structs/src/main.rs
@@ -0,0 +1,32 @@
+#[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 main() {
+ let rect1 = Rectangle {
+ width: 30,
+ height: 50,
+ };
+ let rect2 = Rectangle {
+ width: 3,
+ height: 5,
+ };
+ println!("{:#?}", rect1);
+ println!("The area of the rectangle is {} square pixels.", rect1.area());
+ println!("{}", rect1.can_hold(&rect2));
+}
+