Skip to content
Add traits to structs and enums in version.rs

We can make `Identifier` and `Version` more useful by adding some
traits.  Traits act like interfaces; the compiler knows that a type with
a trait implemented on it can perform certain operations.

src/version.rs
--------------

We can add the [Clone][0], [Debug][1], [PartialEq][2], and [Eq][3]
traits by simply attaching a `derive` attribute.  Rust automatically
generates the code for these traits for us.

To add the [Display][4] trait, we need to implement it ourselves.  We
just need to fill out the `fmt` function for each.  The implementation
for `Version` makes use of the [write! macro][5].

[0]: https://doc.rust-lang.org/core/clone/trait.Clone.html
[1]: https://doc.rust-lang.org/core/fmt/trait.Debug.html
[2]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html
[3]: https://doc.rust-lang.org/core/cmp/trait.Eq.html
[4]: https://doc.rust-lang.org/std/fmt/trait.Display.html
[5]: https://doc.rust-lang.org/std/fmt/#write