Add example on using structs
This commit is contained in:
parent
6be18e3e3e
commit
1dfa283017
2 changed files with 30 additions and 0 deletions
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