Conceptual
Login

Structs and Implementation Blocks in Rust

A struct groups several related values into one named thing, and an implementation block attaches functions to that thing. Together they let you say "this is one device, and here is everything you can do with it" instead of passing six loose variables around. Almost every piece of state a driver keeps lives in a struct you define.

Questions this Concept answers

  • Why does a driver keep its state in one struct instead of several loose variables?