summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-02 17:37:22 -0600
committermo khan <mo@mokhan.ca>2025-06-02 17:37:22 -0600
commit305a98f1fe3d9204fe387865a8f6b8b944f6869c (patch)
treee861a94645d4e3715bcb7116cb28d4b097020cd1
parent52639a5333c992914a6445d77dab397c69aef649 (diff)
Create a struct
-rw-r--r--5.2/Cargo.lock7
-rw-r--r--5.2/Cargo.toml6
-rw-r--r--5.2/src/main.rs27
3 files changed, 40 insertions, 0 deletions
diff --git a/5.2/Cargo.lock b/5.2/Cargo.lock
new file mode 100644
index 0000000..e6ea88d
--- /dev/null
+++ b/5.2/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "struct"
+version = "0.1.0"
diff --git a/5.2/Cargo.toml b/5.2/Cargo.toml
new file mode 100644
index 0000000..0eed17d
--- /dev/null
+++ b/5.2/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "struct"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/5.2/src/main.rs b/5.2/src/main.rs
new file mode 100644
index 0000000..d17839d
--- /dev/null
+++ b/5.2/src/main.rs
@@ -0,0 +1,27 @@
+struct User {
+ active: bool,
+ username: String,
+ email: String,
+ sign_in_count: u64,
+}
+
+fn main() {
+ let user1 = build_user(String::from("root"), String::from("root@example.com"));
+ println!("{}", user1.username);
+
+ let user2 = User {
+ email: String::from("another@example.com"),
+ ..user1
+ };
+
+ println!("{}", user2.username);
+}
+
+fn build_user(email: String, username: String) -> User {
+ User {
+ active: true,
+ username,
+ email,
+ sign_in_count: 1,
+ }
+}