compare_variables
A library for comparing the ordering of variables and producing useful error messages.
This library is based on the struct ComparisonError, which can be used to compare the partial ordering
of two to three variables of any type T which implements the PartialOrd trait. If the comparison evaluates
to false, ComparisonError can be formatted into a nice error message. To simplify the usage, the procedural
macro compare_variables is provided via the feature flag proc_macro (enabled by default).
The full API documentation is available at https://docs.rs/compare_variables/0.1.0/compare_variables/.
Examples
use ;
let x = 1.0;
assert!;
let err: = compare_variables!.unwrap_err;
assert_eq!;
assert!;
// Named struct fields can also be used:
let n = NamedField ;
assert!;
let err: = compare_variables!.unwrap_err;
assert_eq!;
// It is also possible to customize the error message via `as` (providing an alias) and `raw` (omit the variable name):
let x: u16 = 1;
let y: u16 = 2;
let z: u16 = 3;
let err: = compare_variables!.unwrap_err;
assert_eq!;
Usage without the procedural macro
In order to minimize dependencies, it is possible to use this crate without the proc_macro feature flag.
Please see the docstring of ComparisonError for details.
use ;
let x = 1;
let err_macro = compare_variables!.unwrap_err;
let err_no_macro = new.unwrap_err;
assert_eq!;