summaryrefslogtreecommitdiff
path: root/structs
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
downloadlearning-rust-ef1bf4921ee4127d461eec03a14c9070d193345c.tar.xz
learning-rust-ef1bf4921ee4127d461eec03a14c9070d193345c.zip
Init.
Diffstat (limited to 'structs')
-rwxr-xr-xstructs/.gitignore2
-rwxr-xr-xstructs/Cargo.lock4
-rwxr-xr-xstructs/Cargo.toml7
-rwxr-xr-xstructs/src/main.rs32
-rwxr-xr-xstructs/src/main.rs.bak36
5 files changed, 81 insertions, 0 deletions
diff --git a/structs/.gitignore b/structs/.gitignore
new file mode 100755
index 0000000..53eaa21
--- /dev/null
+++ b/structs/.gitignore
@@ -0,0 +1,2 @@
+/target
+**/*.rs.bk
diff --git a/structs/Cargo.lock b/structs/Cargo.lock
new file mode 100755
index 0000000..25b0b72
--- /dev/null
+++ b/structs/Cargo.lock
@@ -0,0 +1,4 @@
+[[package]]
+name = "structs"
+version = "0.1.0"
+
diff --git a/structs/Cargo.toml b/structs/Cargo.toml
new file mode 100755
index 0000000..e61ea2a
--- /dev/null
+++ b/structs/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "structs"
+version = "0.1.0"
+authors = ["Adam Carpenter <carpenat@ES.AD.ADP.COM>"]
+edition = "2018"
+
+[dependencies]
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));
+}
+
diff --git a/structs/src/main.rs.bak b/structs/src/main.rs.bak
new file mode 100755
index 0000000..361b225
--- /dev/null
+++ b/structs/src/main.rs.bak
@@ -0,0 +1,36 @@
+struct User {
+ username: String,
+ email: String,
+ sign_in_count: u64,
+ active: bool,
+}
+
+fn main() {
+// let mut user1 = User {
+// email: String::from("test@tester.net"),
+// username: String::from("testytester"),
+// active: true,
+// sign_in_count: 999,
+// };
+// let user1 = build_user(String::from("dennis.nedry@adp.com"), String::from("nedryland"));
+// let user2 = User {
+// email: String::from("john.hammond@adp.com"),
+// username: String::from("spare_no_expense"),
+// ..user1
+// };
+// println!("{} {} {} {}", user2.email, user2.username, user2.active, user2.sign_in_count);
+
+ struct Color(u32, u32, u32);
+ struct Point(i32, i32, i32);
+ let black = Color(0, 0, 0);
+ let origin = Point(0, -1, 0);
+}
+
+fn build_user(email: String, username: String) -> User {
+ User {
+ email,
+ username,
+ active: true,
+ sign_in_count: 1,
+ }
+}