pets 0.1.2

Predicate existential types.
Documentation
std_prelude!();
use crate::{Pet, PetRef, Pred};

/// Convenience extension for `Pred`.
pub trait PredExt<T: ?Sized>: Pred<T> {
    /// Attempts to create a `Pet` of this predicate with the given value.
    fn pet(t: T) -> Option<Pet<T, Self>>
    where
        T: Sized;
    /// Creates a `Pet` of this predicate with the given value.
    unsafe fn pet_unchecked(t: T) -> Pet<T, Self>
    where
        T: Sized;
    /// Attempts to create a `PetRef` of this predicate with the given reference.
    fn petref<'a>(t: &'a T) -> Option<PetRef<'a, T, Self>>;

    /// Creates a `PetRef` of this predicate with the given reference.
    unsafe fn petref_unchecked<'a>(t: &'a T) -> PetRef<'a, T, Self>;
}

impl<T: ?Sized, P: Pred<T>> PredExt<T> for P {
    fn pet(t: T) -> Option<Pet<T, P>>
    where
        T: Sized,
    {
        Pet::new(t)
    }
    unsafe fn pet_unchecked(t: T) -> Pet<T, P>
    where
        T: Sized,
    {
        Pet::new_unchecked(t)
    }
    fn petref<'a>(t: &'a T) -> Option<PetRef<'a, T, P>> {
        PetRef::new(t)
    }
    unsafe fn petref_unchecked<'a>(t: &'a T) -> PetRef<'a, T, P> {
        PetRef::new_unchecked(t)
    }
}