Avoiding missing implementations

There are a couple of traits we probably want many of our types to implement. The first of them is the Debug trait. The Debug trait should probably be implemented by all of our types, since it enables a developer to print debug information about our structures, enumerations, and so on. Moreover, it allows a user of our API to derive the Debug trait in structures using our API types by only adding an attribute.

We can enforce the implementation of this trait for all of our types by adding #![warn(missing_debug_implementations)]. The only detail is that this trait will only check for types exposed in our API. So, it will only work for pub types.

Another interesting trait is the Copy trait. Sometimes, we create a small structure with a couple of integers that would work best if copied in certain cases, as we saw in the previous chapters. The problem is that if we forget about implementing it, we might end up doing excessive referencing, making our code slower. We can solve this by adding this lint: #![warn(missing_copy_implementations)].

This lint has a couple of caveats though. It will only work for pub types, as in the case for the Debug implementation lint, and it will lint all structures that all of its members are Copy types. This means that if we have a really big structure that we wouldn't like to copy around, we will need to allow the lint for that particular structure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156