Created
March 23, 2019 06:16
-
-
Save DoumanAsh/051969c9ad09f4029d596cabf1f4eef9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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