Rust

Trait Bounds in Rust

RustTraitsGenericsadvanced

A bound constrains a type parameter to types providing certain behaviour, so one function serves many types with no runtime cost.

expected output

7 1.5

Why practise typing this

Typing traits 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 →