sigma_types

Trait Test

Source
pub trait Test<Input, const ARITY: usize = 1> {
    type Error<'i>: Display
       where Input: 'i;

    const ADJECTIVE: &str;

    // Required method
    fn test(input: [&Input; ARITY]) -> Result<(), Self::Error<'_>>;
}
Expand description

Function-like type that checks an invariant and optionally provides an error message.

Takes an arity parameter useful e.g. for comparing pairs, since you want to take references for each element of the pair, but the pair itself has to be a temporary value.

Required Associated Constants§

Source

const ADJECTIVE: &str

Adjective to describe this test: for example, if we’re testing A, then this is B in “A is not B.”

Required Associated Types§

Source

type Error<'i>: Display where Input: 'i

An error implementing ::core::fmt::Display. If no error is ever provided, please use ::core::convert::Infallible.

Required Methods§

Source

fn test(input: [&Input; ARITY]) -> Result<(), Self::Error<'_>>

Check whether a given term satisfies this invariant.

§Errors

If it doesn’t.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Input: Debug + PartialOrd + Zero> Test<Input> for NonNegativeInvariant<Input>

Source§

const ADJECTIVE: &str = "non-negative"

Source§

type Error<'i> = Negative<'i, Input> where Input: 'i

Source§

impl<Input: Debug + PartialOrd + Zero> Test<Input> for PositiveInvariant<Input>

Source§

const ADJECTIVE: &str = "positive"

Source§

type Error<'i> = NonPositive<'i, Input> where Input: 'i

Source§

impl<Input: One + PartialOrd + Zero + Debug, const INCLUSIVE_AT_ZERO: bool, const INCLUSIVE_AT_ONE: bool> Test<Input> for OnUnitInvariant<Input, INCLUSIVE_AT_ZERO, INCLUSIVE_AT_ONE>

Source§

const ADJECTIVE: &str = "on the unit interval"

Source§

type Error<'i> = NotOnUnit<'i, Input, INCLUSIVE_AT_ZERO, INCLUSIVE_AT_ONE> where Input: 'i

Source§

impl<Invariant: Test<Input::Item, 1>, Input: IntoIterator + Debug> Test<Input> for All<Invariant, Input>
where Input::Item: Debug, for<'i> &'i Input: IntoIterator<Item = &'i Input::Item>,

Source§

const ADJECTIVE: &str = "all valid"

Source§

type Error<'i> = NotAll<'i, <Input as IntoIterator>::Item, Invariant> where Input: 'i

Source§

impl<Invariant: Test<Input::Item, 2>, Input: IntoIterator + Debug> Test<Input> for AllPairs<Invariant, Input>
where Input::Item: Debug, for<'i> &'i Input: IntoIterator<Item = &'i Input::Item>,

Source§

const ADJECTIVE: &str = "all pairwise valid"

Source§

type Error<'i> = NotAllPairs<'i, <Input as IntoIterator>::Item, Invariant> where Input: 'i

Source§

impl<const ALLOW_DUPLICATES: bool, Input: PartialOrd> Test<Input, 2> for SortedPair<ALLOW_DUPLICATES>

Source§

const ADJECTIVE: &str = "sorted"

Source§

type Error<'i> = OutOfOrder where Input: 'i