I'm writing a library to deparse GDTF Global Device Type Format in entertainment industry files.
The Format is a tree of a lot of structs. On some structs I want to implement
PartialEq for anyone to uses the library to be able to compare some structs. In a lot of these cases it would not be intuitive if they match in any case, even when the data structure is the same.
The struct DataVersion contains the GDTF Version the file was created with. I want to be able to compare this versions but I don't want to return true if the Version is not known / not yet supported by the library
assert_eq!(DataVersion::Version1_0, DataVersion::Version1_0); assert_ne!(DataVersion::Unknown, DataVersion::Unknown);
So far so good but I want to write test to be able to compare
DataVersion::Unknown. I've created a new trait
AssertEqAllowEmpty for that reason.
To keep code slim and not to confuse anyone using this library I've added
#[cfg(test)] to this trait.
When starting to get better documentation on every method, the common way is to use
assert_eq!. You are able to test this code also to be sure your doc is correct what is great!
But when I now would write somthing like
assert_ne!(DataVersion::Unknown, DataVersion::new_from_str("1.something invalid"));
in the documentation, I would be really confused as user because they are the same in that context.
Also I can't document it like
because this method exists only in testing context.
What would you suggest is best practice to solve all this problems?