Skip to content

Traits practice problems in Rust

Difficulty:
Category & tags Filters active
Category:
Tag:

Showing 42 of 42

Title Difficulty
Accept string-like values with AsRef Medium
Associated type or generic parameter? Hard
Blanket implementations: shared behavior and overlap Hard
Box<dyn Trait>: trait objects, DSTs and dynamic dispatch Medium
BTreeMap range queries Medium
Build a CSV record with one output buffer Easy
Capstone: compose parser errors and their causes Hard
Choose the intended method through a wrapper Medium
Compare weighted records without requiring Eq Medium
Convert distances with tuple and unit structs Easy
Convert temperatures with From and Into Medium
Cow in API design: impl Into<Cow<str>> Hard
Define a structured validation error Medium
Delegate shape methods through an enum Medium
Derive consistent ordering for versions and priorities Medium
#[derive(Debug)] and the three shapes of debug output Easy
Expose a string view with Deref Medium
Extension traits: adding methods to types you do not own Medium
Fn, FnMut, FnOnce: the closure hierarchy Medium
Format money with Display Easy
From impls: the machinery behind ? Medium
From, Into, TryFrom: conversions that cannot lie Medium
Generics, traits and lifetimes in one signature Medium
Implement a custom hasher for integer keys Hard
Implementing traits with a newtype Hard
Implement Iterator by hand: the Collatz sequence Medium
Keep concrete methods while enabling trait objects Hard
Look up and update HashMap values Easy
Make hashing agree with equality Medium
Make your own collection iterable, all three ways Hard
Operator overloading: + is just a trait method Medium
Replace a manual default with a derive Easy
Sealed traits: public to use, closed to implement Medium
SemVer for Rust APIs: what actually breaks Hard
size_hint and DoubleEndedIterator: an iterator with two ends Hard
Sum collections and iterators with IntoIterator Medium
Supertraits and default methods Medium
The Future trait: Output, Poll, and your first hand-written future Easy
Traits as shared behaviour Easy
TryFrom and TryInto: validate a percentage Medium
use declarations: nested groups, as, self, and _ Medium
Write your own adapters, with an extension trait Hard