Used to navigate the hierarchy of crates, modules, and types. It essentially means "look inside."
- Crate/Module Access:
std::fs(Thefsmodule inside thestdcrate). - Associated Functions:
Path::new()(Thenewfunction belonging to thePathstruct). - Enum Variants:
Result::Ok(TheOkvariant inside theResultenum).
A placeholder for macros (like println!) used to inspect complex types.
{}(Display): Only for types with a clear "user-facing" string version (likei32orString).{:?}(Debug): For types without a default string version (likePath,Vec, orResults). It prints the internal structure for developers.{:#?}(Pretty Debug): Same as{:?}but adds indentation and newlines—useful for large structs.
A Trait defines a set of methods that different types can share.
- The Rule: To use a trait's methods, you must
usethe trait at the top of the file. - Abstraction: Functions can accept
impl Traitinstead of a specific type, making code hardware-agnostic. - Analogy: - Trait: A "Driver's License" (Requirement: steer, brake).
- Struct: A "Tesla" or "Truck" (The specific data/hardware).
- Instance: Your specific car in the driveway (
let mut my_car = ...).