pets 0.1.2

Predicate existential types.
Documentation
//! Static predicate traits.

use std::fmt::Debug;
std_prelude!();

/// A predicate over a single variable.
///
/// For a given `T` implementing `Predicate`,
/// `T::default().fmt(..)`` should print the name
/// of the predicate, with angle brackets to indicate
/// generic predicate parameters.
pub trait Pred<T: ?Sized>: Default + Debug + Copy {
    /// Attempts to accept a single `value`.
    fn accept(value: &T) -> bool;
}

/// A predicate over two variables.
pub trait Pred2<T: ?Sized>: Default + Debug + Copy {
    /// Attempts to accept a pair `(a, b)`.
    fn accept(a: &T, b: &T) -> bool;

    /// Attempts to accept a pair `(a, b)`.
    fn accept_tup((a, b): (&T, &T)) -> bool {
        Self::accept(a, b)
    }
}