diff options
Diffstat (limited to 'meap/meap-code/ch1/ch1-save-user-data.rs')
-rw-r--r-- | meap/meap-code/ch1/ch1-save-user-data.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/meap/meap-code/ch1/ch1-save-user-data.rs b/meap/meap-code/ch1/ch1-save-user-data.rs new file mode 100644 index 0000000..48f8130 --- /dev/null +++ b/meap/meap-code/ch1/ch1-save-user-data.rs @@ -0,0 +1,32 @@ +use std::str;
+
+#[derive(Debug)]
+struct User {
+ id: u8,
+ secret: String,
+}
+
+fn store_secrets(user: &User, buffer: &mut[u8]) {
+ let _secret = user.secret.clone();
+
+
+ // assume we're writing to a database
+ println!("{:?}: {}", user, str::from_utf8(&buffer).unwrap());
+}
+
+fn main() {
+ let buffer = &mut[0u8; 1024];
+ let u1 = User {
+ id: 1,
+ secret: String::from("Pa55w0rd!"),
+ };
+ let u2 = User {
+ id: 2,
+ secret: String::from("correct horse battery staple"),
+ };
+
+ store_secrets(&u1, buffer);
+ store_secrets(&u2, buffer);
+
+
+}
\ No newline at end of file |