diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-08-06 15:06:18 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-08-06 15:06:18 -0300 |
commit | f24123f943abaebffd098a12069bcca62181f862 (patch) | |
tree | dd36cc3cafc0ec71fc388b610ec127bb53b657bf /src/lib.rs | |
parent | a8778ff35bde88bb63d9fec769edf66e68d7969e (diff) |
Fix predicates
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs index 8fa727f..a3a6e1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,15 +106,34 @@ mod vm; pub use pattern::Pattern; /// A predicate. -pub type Predicate = dyn (for<'x, 'de, 'a> Fn( - &'x (dyn 'a + erased_serde::Deserializer<'de>) +pub type Predicate = dyn (Fn( + &mut dyn erased_serde::Deserializer<> ) -> bool) + Send + Sync; -/// Helper to build predicates because HRTB inference is the worst. +/// Helper to build predicates because closure inference is the worst. +/// +/// # Examples +/// +/// This doesn't work: +/// +/// ```rust compile_fail +/// use serde::Deserialize; +/// use datafu::Predicate; +/// +/// let x = Box::new(|v| String::deserialize(v).is_ok()) as Box<Predicate>; +/// ``` +/// +/// But this does: +/// +/// ```rust +/// use serde::Deserialize; +/// +/// let x = datafu::pred(|v| String::deserialize(v).is_ok()); +/// ``` pub fn pred<F>(f: F) -> Box<Predicate> where - F: (for<'x, 'de, 'a> Fn( - &'x (dyn 'a + erased_serde::Deserializer<'de>) + F: (Fn( + &mut dyn erased_serde::Deserializer<> ) -> bool) + Send + Sync + 'static, { Box::new(f) |