From 1dfa283017b974f067c27c4f561e5160cbce41c2 Mon Sep 17 00:00:00 2001 From: laurens Date: Fri, 22 May 2020 13:40:09 +0200 Subject: [PATCH] Add example on using structs --- struct_example/Cargo.toml | 9 +++++++++ struct_example/src/main.rs | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 struct_example/Cargo.toml create mode 100644 struct_example/src/main.rs diff --git a/struct_example/Cargo.toml b/struct_example/Cargo.toml new file mode 100644 index 0000000..cb236a4 --- /dev/null +++ b/struct_example/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "struct_example" +version = "0.1.0" +authors = ["laurens "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/struct_example/src/main.rs b/struct_example/src/main.rs new file mode 100644 index 0000000..ad62ffb --- /dev/null +++ b/struct_example/src/main.rs @@ -0,0 +1,21 @@ +#[derive(Debug)] +struct User { + email: String, + username: String, + active: bool, + sign_in_count: u32, +} + +fn build_user(email: String, username: String) -> User { + User { + email, + username, + active: true, + sign_in_count: 0, + } +} + +fn main() { + let user = build_user(String::from("Heisenberg"), String::from("mail@mail.com")); + println!("Hello to the User: {:?}!", user); +}