pets 0.1.2

Predicate existential types.
Documentation
//! Provided implementations for common predicates.

use crate::{Pred, Pred2};
std_prelude!();

#[derive(Clone, Copy, Debug, Default)]
/// Accepts pairs `(a, b)` where `a <= b`.
pub struct Increasing;

impl<T: PartialOrd + ?Sized> Pred2<T> for Increasing {
    fn accept(a: &T, b: &T) -> bool {
        a.le(b)
    }
}

#[derive(Clone, Copy, Debug, Default)]
/// Accepts pairs `(a, b)` where `a >= b`.
pub struct Decreasing;

impl<T: PartialOrd + ?Sized> Pred2<T> for Decreasing {
    fn accept(a: &T, b: &T) -> bool {
        a.ge(b)
    }
}

#[derive(Clone, Copy, Debug, Default)]
/// Accepts everything.
pub struct True;

impl<T> Pred<T> for True {
    fn accept(_: &T) -> bool {
        true
    }
}

#[derive(Clone, Copy, Debug, Default)]
/// Accepts nothing.
pub struct False;

impl<T> Pred<T> for False {
    fn accept(_: &T) -> bool {
        false
    }
}

mod iter;
pub use iter::*;

#[cfg(feature = "num-integer")]
mod integer;

#[cfg(feature = "num-integer")]
pub use integer::*;

/// Accepts iterators where each element is less than or equal to the next.
pub type Ascending = AllAdj<Increasing>;

/// Accepts iterators where each element is greater than or equal to the next.
pub type Descending = AllAdj<Decreasing>;