Skip to main content

Implementing Display and From

`Debug` is for developers, `Display` is for users. `Display` cannot be derived, because only you know how the value should read in a sentence — so you write one `fmt` method.

Implementing `Display` also gets you `.to_string()` for free through the blanket `ToString` implementation. One impl, two capabilities.

`From` is the conversion trait. Implement `From<A> for B` and you automatically get `A::into()` as well, plus `?` conversions in error handling later on.

Run it and change it

The editor below is live: edit anything and the real compiler output updates by itself.

Your Rust