There are two types of trait derivations: built-in derives and custom derives. We will talk about the second ones in Chapter 9, Creating Your Own Macros, but let's see what deriving can help us achieve. Let's imagine the following structure:
struct MyData { field1: String, field2: u64,}
It's recommended that every structure implements the Debug trait so that if, for example, we need to debug what is happening with some part of the code, we can use the println!("{:?}", element); syntax. It should show the contents of the fields, so we could imagine something like the following:
use std::fmt;impl fmt::Debug for MyData { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "MyData {{ field1: \"{}\", field2: {} ...