Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 614 Bytes

README.md

File metadata and controls

32 lines (27 loc) · 614 Bytes

Ownership of struct data

In the code here User struct definition owns all its fields/members. If we specified this instead -

struct User {
    username: &str,
    email: &str,
    active: bool,
    signin_count: u64,
}

fn main() {
	let user = User{
	    email: "[email protected]",
	    username: "someone",
	    active: true,
	    signin_count: 3,
	};
}

The above won't work because it is missing lifetime parameter. Check Chapter 10 for lifetimes.

struct User<'a> {
    username: &'a str,
    email: &'a 'str,
    active: bool,
    signin_count: u64,
}