<p>We can of course do this: <code>println!("{:?}", my_number.0 + 20);</code>. But then we are just adding a separate <code>u8</code> to the 20. It would be nice if we could just add them together. The message <code>cannot be dereferenced</code> gives us a clue: we need to implement <code>Deref</code>. Something simple that implements <code>Deref</code> is sometimes called a "smart pointer". A smart pointer can point to its item, has information about it, and can use its methods. Because right now we can add <code>my_number.0</code>, which is a <code>u8</code>, but we can't do much else with a <code>HoldsANumber</code>: all it has so far is <code>Debug</code>.</p>
<p>Interesting fact: <code>String</code> is actually a smart pointer to <code>&str</code> and <code>Vec</code> is a smart pointer to array (or other types). So we have actually been using smart pointers since the beginning.</p>
<p>Implementing <code>Deref</code> is not too hard and the examples in the standard library are easy. <ahref="https://doc.rust-lang.org/std/ops/trait.Deref.html">Here's the sample code from the standard library</a>:</p>
<p>We can of course do this: <code>println!("{:?}", my_number.0 + 20);</code>. But then we are just adding a separate <code>u8</code> to the 20. It would be nice if we could just add them together. The message <code>cannot be dereferenced</code> gives us a clue: we need to implement <code>Deref</code>. Something simple that implements <code>Deref</code> is sometimes called a "smart pointer". A smart pointer can point to its item, has information about it, and can use its methods. Because right now we can add <code>my_number.0</code>, which is a <code>u8</code>, but we can't do much else with a <code>HoldsANumber</code>: all it has so far is <code>Debug</code>.</p>
<p>Interesting fact: <code>String</code> is actually a smart pointer to <code>&str</code> and <code>Vec</code> is a smart pointer to array (or other types). So we have actually been using smart pointers since the beginning.</p>
<p>Implementing <code>Deref</code> is not too hard and the examples in the standard library are easy. <ahref="https://doc.rust-lang.org/std/ops/trait.Deref.html">Here's the sample code from the standard library</a>:</p>