Assert closure provided to Subscription::map is non-capturing
This commit is contained in:
parent
f39a5fd895
commit
2470a3fb40
1 changed files with 12 additions and 4 deletions
|
|
@ -89,14 +89,22 @@ impl<Message> Subscription<Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transforms the [`Subscription`] output with the given function.
|
/// Transforms the [`Subscription`] output with the given function.
|
||||||
pub fn map<A>(
|
///
|
||||||
mut self,
|
/// # Panics
|
||||||
f: impl Fn(Message) -> A + MaybeSend + Clone + 'static,
|
/// The closure provided must be a non-capturing closure. The method
|
||||||
) -> Subscription<A>
|
/// will panic in debug mode otherwise.
|
||||||
|
pub fn map<F, A>(mut self, f: F) -> Subscription<A>
|
||||||
where
|
where
|
||||||
Message: 'static,
|
Message: 'static,
|
||||||
|
F: Fn(Message) -> A + MaybeSend + Clone + 'static,
|
||||||
A: 'static,
|
A: 'static,
|
||||||
{
|
{
|
||||||
|
debug_assert!(
|
||||||
|
std::mem::size_of::<F>() == 0,
|
||||||
|
"the closure {} provided in `Subscription::map` is capturing",
|
||||||
|
std::any::type_name::<F>(),
|
||||||
|
);
|
||||||
|
|
||||||
Subscription {
|
Subscription {
|
||||||
recipes: self
|
recipes: self
|
||||||
.recipes
|
.recipes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue