Structs

You will learn

How to declare a struct and a packed struct, and how many a module may hold.

pub struct Point { x: i32, y: i32 } declares a type with two fields. Fields are a name and a type, separated by commas. A packed struct lays its fields next to each other with no padding, the shape a hardware register has. A module may declare several structs; the lesson spec has two, and the verdict stays clean on all 7 backends.

Open the interactive lesson →