From 95aaa2790a75e9e5476a53ff52d324b4201ef39b Mon Sep 17 00:00:00 2001
From: Jordan Gong <jordan.gong@protonmail.com>
Date: Thu, 13 Aug 2020 16:47:02 +0800
Subject: Introduce structs

---
 structure/.gitignore  | 18 ++++++++++++++++++
 structure/Cargo.toml  |  9 +++++++++
 structure/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 structure/.gitignore
 create mode 100644 structure/Cargo.toml
 create mode 100644 structure/src/main.rs

diff --git a/structure/.gitignore b/structure/.gitignore
new file mode 100644
index 0000000..e629269
--- /dev/null
+++ b/structure/.gitignore
@@ -0,0 +1,18 @@
+
+# Created by https://www.toptal.com/developers/gitignore/api/rust
+# Edit at https://www.toptal.com/developers/gitignore?templates=rust
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# End of https://www.toptal.com/developers/gitignore/api/rust
+
diff --git a/structure/Cargo.toml b/structure/Cargo.toml
new file mode 100644
index 0000000..087ac90
--- /dev/null
+++ b/structure/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "structure"
+version = "0.1.0"
+authors = ["Jordan Gong <jordan.gong@protonmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/structure/src/main.rs b/structure/src/main.rs
new file mode 100644
index 0000000..81df2d9
--- /dev/null
+++ b/structure/src/main.rs
@@ -0,0 +1,43 @@
+/* define */
+struct User {
+    username: String,
+    email: String,
+    sign_in_count: u64,
+    active: bool,
+}
+
+/* tuple structs */
+struct Color(i32, i32, i32);
+struct Point(i32, i32, i32);
+
+fn main() {
+    /* create an instance */
+    let mut user1 = User {
+        email: String::from("someone@example.com"),
+        username: String::from("someusername123"),
+        active: true,
+        sign_in_count: 1,
+    };
+
+    user1.email = String::from("anotheremal@example.com");
+
+    /* update syntax */
+    let user2 = User {
+        email: String::from("another@email.com"),
+        username: String::from("anotherusername567"),
+        ..user1
+    };
+
+    let black = Color(0, 0, 0);
+    let origin = Point(0, 0, 0);
+}
+
+fn build_user(email: String, username: String) -> User {
+    User {
+        email,  /* field init shorthad */
+        username,
+        active: true,
+        sign_in_count: 1,
+    }
+}
+
-- 
cgit v1.2.3