Rust

Box For Recursive Types in Rust

RustSmart PointersBoxadvanced

A recursive type has no fixed size, so the recursive field must sit behind a pointer. Box is the simplest heap allocation.

expected output

Cons(1, Cons(2, Nil))

Why practise typing this

Typing smart pointers 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 →