-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Labels
enhancementImprove the expectedImprove the expected
Description
Predicates such as FnPredicate use PhantomData<T> to bypass the requirement that all generic parameters must be used. This makes the compiler think that predicate owns an instance of T, leading to two effects:
- if
Tis bound by lifetime'a, then the predicate will also be bound by'a, - if
Tis notSendorSync, the predicate will also not beSendorSync.
There's nothing we can do about the first one. The second one, however, can be remedied by manually implementing Send and Sync.
For FnPredicate it will look like this:
unsafe impl<F, T> Send for FnPredicate<F, T>
where
F: Fn(&T) -> bool + Send,
T: ?Sized,
{
}
unsafe impl<F, T> Sync for FnPredicate<F, T>
where
F: Fn(&T) -> bool + Sync,
T: ?Sized,
{
}This change will add unsafe to the crate. The benefit is that predicates will be easier to use in multi-threaded environments.
Metadata
Metadata
Assignees
Labels
enhancementImprove the expectedImprove the expected