trait_guard
trait_guard is a macro used to protect a trait implementation from usage with a custom message, note, and label.
It abuses the on_unimplemented attribute to provide a custom error message when the trait is not implemented. It requires
the negative_impls and trivial_bounds nightly features to be enabled.
You can use any trait (even if it's an STD trait or from another crate)!
Installation
To use trait_guard, run the following command in your terminal:
Example usage:
trait_guard!;
The example above will refuse to compile if the MyTrait implementation of MyType is used anywhere in the user's code.
If you want to guard multiple traits/types, you can change the name of trait_guard and guard_struct to avoid conflicts.
Example for [std::fmt::Display]
use trait_guard;
;
trait_guard!;