From f24123f943abaebffd098a12069bcca62181f862 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 6 Aug 2022 15:06:18 -0300 Subject: Fix predicates --- src/lib.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') 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; +/// ``` +/// +/// But this does: +/// +/// ```rust +/// use serde::Deserialize; +/// +/// let x = datafu::pred(|v| String::deserialize(v).is_ok()); +/// ``` pub fn pred(f: F) -> Box 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) -- cgit 1.4.1