struct
from The Rust Programming Language
struct name {
value: type
}
Structs are similar to tuples, discussed in âThe Tuple Typeâ section, in that both hold multiple related values. Like tuples, the pieces of a struct can be different types. Unlike with tuples, in a struct youâll name each piece of data so itâs clear what the values mean. Adding these names means that structs are more flexible than tuples: You donât have to rely on the order of the data to specify or access the values of an instance.
To define a struct, we enter the keyword struct and name the entire struct. A structâs name should describe the significance of the pieces of data being grouped together. Then, inside curly brackets, we define the names and types of the pieces of data, which we call fields. For example, Listing 5-1 shows a struct that stores information about a user account.
Example struct
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
You can call a struct from a function.
Example struct from function
// struct declared previously
  fn build_user(email: String, username: String) -> User{
    User{
      active: true,
      email,
      username,
      sign_in_count: 1,
    }
   Â
    let user3 = build_user("email@email.com".to_string(), "username".to_string());
  println!("The user's email is {} and the sign-in count is {}", user3.email, user3.sign_in_count);
You can create instances from other instances. Use the syntax ..struct1 to fill in values from that instance
Example instances from instance
  let user2 = User{
    email: String::from("another@m.com");
    ..user1
  }
Tuple structs are like other structs but don't have named values
Example tuple struct
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
let black = Color(0, 0, 0);
let white = Color(255, 255, 255);
Unit-like structs have no fields and used when you need a type to implement a trait but don't need to store data.
Example unit-like struct
``
  struct AlwaysEqual;  let subject = AlwaysEqual; Â