Consistency checking


#1

When debugging application, I need sometimes to do expensive consistency-checks, not just asserts.
I have few questions regarding this.

1.) How to make some code enabled only on test or disabled on released version of binary?
2.) Can I enable/disable ASSERT macros?
3.) Would it be a good idea to insert consistency-checks inside Debug::fmt()? Both are used only for debugging.


#2

1.) #[cfg(debug_assertions)] (assuming you really mean test and not debug then #[cfg(test)] )
2.) Cargo features #[cfg(feature = "uscell")] (this is one name I have added once to have build switch from RefCell to UnsafeCell.)
You also can use debug_assert! macros.
3.) Yes. Some code I have uses (1) to enable Drop trait implementation that does a sanity check.


#3
  1. If this is a public type in a library, then I wouldn’t. (Or at least, the checks should be behind a cfg(feature = "debug-checks")). It would affect anybody who puts an instance of your struct on one of theirs and uses #[derive(Debug)].
    If it’s just an application or personal project, then go nuts.