Add example on using structs
This commit is contained in:
parent
6be18e3e3e
commit
1dfa283017
2 changed files with 30 additions and 0 deletions
9
struct_example/Cargo.toml
Normal file
9
struct_example/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "struct_example"
|
||||
version = "0.1.0"
|
||||
authors = ["laurens <miers132@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
21
struct_example/src/main.rs
Normal file
21
struct_example/src/main.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue