Constants

You will learn

The six pieces of a constant declaration and what each one does.

pub const WIDTH : u8 = 8; reads left to right: pub makes the name visible to other modules, const says the value is fixed, WIDTH is the name, u8 is the type, 8 is the value, and the semicolon ends it. Constants are what this site's test runner can check: the lesson spec declares WIDTH, HEIGHT and AREA and tests that 8 times 4 is 32.

Open the interactive lesson →