diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 4d5a1192..1ee291c1 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -89,14 +89,22 @@ impl Subscription { } /// Transforms the [`Subscription`] output with the given function. - pub fn map( - mut self, - f: impl Fn(Message) -> A + MaybeSend + Clone + 'static, - ) -> Subscription + /// + /// # Panics + /// The closure provided must be a non-capturing closure. The method + /// will panic in debug mode otherwise. + pub fn map(mut self, f: F) -> Subscription where Message: 'static, + F: Fn(Message) -> A + MaybeSend + Clone + 'static, A: 'static, { + debug_assert!( + std::mem::size_of::() == 0, + "the closure {} provided in `Subscription::map` is capturing", + std::any::type_name::(), + ); + Subscription { recipes: self .recipes