Assure: macros for Rust runtime checking
This Rust crate provides the macro assure! and related macros.
These macros are similar to the macro assert! and related macros.
Available via https://crates.io/crates/assure
Introduction
The assure! macros work like this:
-
assure!(condition)will returnResultwithOk(true)orErr("assure"). -
assure!(condition, message)will returnResultwithOk(true)orErr(message).
Whereas assert! macros work like this:
-
assert!(condition)will return successfully or will callpanic!. -
assert!(condition, message)will return successfully or will callpanic!with the message.
Macros for simple values
Macro for truth checking:
assure!(a): assureais true.
Macros for value comparison:
-
assure_eq!(a, b): assureais equal tob. -
assure_ne!(a, b): assureais not equal tob. -
assure_lt!(a, b): assureais less thanb. -
assure_le!(a, b): assureais less than or equal tob. -
assure_gt!(a, b): assureais greater thanb. -
assure_ge!(a, b): assureais greater than or equal tob.
Examples:
assure_eq!
!
!
Macros for bag checking
These macros help with order-independent comparison of iterator bag parameters, such as comparison of two arrays, or two vectors.
assure_bag_eq(a, b): assure the bagais equal to the bagb.
Examples:
assure_set_eq!
!
!
Macros for set checking
These macros help with order-independent comparison of iterator set parameters, such as comparison of two arrays, or two vectors.
-
assure_set_eq(a, b): assure the setais equal to the setb. -
assure_set_ne(a, b): assure the setais not equal to the setb.
Examples:
assure_set_eq!
!
!
Macros for IO-related checking
These macros help with IO-related checking, such as comparison of files, streams, etc. These macros return a Result with Ok(true) or Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, message)).
Macro for truth checking:
assure_io!(a): assureais true.
Macros for value comparison:
-
assure_io_eq!(a, b): assureais equal tob. -
assure_io_ne!(a, b): assureais not equal tob. -
assure_io_lt!(a, b): assureais less thanb. -
assure_io_le!(a, b): assureais less than or equal tob. -
assure_io_gt!(a, b): assureais greater thanb. -
assure_io_ge!(a, b): assureais greater than or equal tob.
assure_io_eq!
!
!