Skip to content

Instantly share code, notes, and snippets.

@DoumanAsh
Created March 23, 2019 06:16
Show Gist options
  • Save DoumanAsh/051969c9ad09f4029d596cabf1f4eef9 to your computer and use it in GitHub Desktop.
Save DoumanAsh/051969c9ad09f4029d596cabf1f4eef9 to your computer and use it in GitHub Desktop.
pub trait UnaryPredicate<T> {
#[doc(hidden)]
fn call(&self, val: &T) -> bool;
}
impl<T: PartialEq> UnaryPredicate<T> for T {
#[inline(always)]
fn call(&self, val: &T) -> bool {
self == val
}
}
impl<T: PartialEq> UnaryPredicate<T> for &T {
#[inline(always)]
fn call(&self, val: &T) -> bool {
*self == val
}
}
impl<T, F: Fn(&T) -> bool> UnaryPredicate<T> for F {
#[inline(always)]
fn call(&self, val: &T) -> bool {
self(val)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment