sigma_types/invariant.rs
1//! Function-like type that checks an invariant and optionally provides an error message.
2
3use core::fmt;
4
5/// Function-like type that checks an invariant and optionally provides an error message.
6///
7/// Takes an arity parameter useful e.g. for comparing pairs, since
8/// you want to take references for each element of the pair,
9/// but the pair *itself* has to be a temporary value.
10pub trait Test<Input, const ARITY: usize = 1> {
11 /// Adjective to describe this test:
12 /// for example, if we're testing A,
13 /// then this is B in "A is not B."
14 const ADJECTIVE: &str;
15
16 /// An error implementing `::core::fmt::Display`.
17 /// If no error is ever provided, please use `::core::convert::Infallible`.
18 type Error<'i>: fmt::Display
19 where
20 Input: 'i;
21
22 /// Check whether a given term satisfies this invariant.
23 /// # Errors
24 /// If it doesn't.
25 fn test(input: [&Input; ARITY]) -> Result<(), Self::Error<'_>>;
26}