Structs are similar to tuples — both hold multiple related values. Example:
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64, }
Method Syntax
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
}
Using impl, you can associate methods to structs. Method syntax removes need to create a function that takes in a reference to the struct.
Nested Paths
use std::cmp::Ordering;
use std::io;
// simplify to:
use std::{cmp::Ordering, io};
// or:
use std::io;
use std::io::Write;
// to:
use std::io {self, Write};
Glob Operatior
use std::collections::*
Imports all public items in path