Skip to main content

Structs, traits and behaviour

Rust has no classes and no inheritance. You describe data with `struct` and shared behaviour with `trait`, and the compiler wires them together with zero runtime cost.

Step 1 of 3

Describe the data

Define a struct with at least two fields, create one, and print a field.

A struct is just a named layout. There is no hidden vtable or object header unless you ask for one.

Checkpoints

  • A struct with fields is defined — not yet passed
  • The program compiles and runs without errors — not yet passed
  • Something is printed — not yet passed