Rust

Impl Blocks in Rust

RustStructsMethodsbeginner

Methods live in an impl block. Those taking &self are called on an instance; those without a self parameter act as constructors.

expected output

12

Why practise typing this

Typing structs code builds muscle memory for the symbols and indentation Rust uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More Rust practice

Browse all Rust snippets →