diff options
| author | 2024-02-05 21:34:35 +0100 | |
|---|---|---|
| committer | 2024-02-05 21:34:35 +0100 | |
| commit | 2470a3fb40c08b0017d47e7e5a4e8e7255f65919 (patch) | |
| tree | 0f71240a7df89809a903ebf4677ea38dfd0ca3db /futures/src | |
| parent | f39a5fd8953494fd8e41c05bc053519740d09612 (diff) | |
| download | iced-2470a3fb40c08b0017d47e7e5a4e8e7255f65919.tar.gz iced-2470a3fb40c08b0017d47e7e5a4e8e7255f65919.tar.bz2 iced-2470a3fb40c08b0017d47e7e5a4e8e7255f65919.zip | |
Assert closure provided to `Subscription::map` is non-capturing
Diffstat (limited to '')
| -rw-r--r-- | futures/src/subscription.rs | 16 | 
1 files changed, 12 insertions, 4 deletions
| 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<Message> Subscription<Message> {      }      /// Transforms the [`Subscription`] output with the given function. -    pub fn map<A>( -        mut self, -        f: impl Fn(Message) -> A + MaybeSend + Clone + 'static, -    ) -> Subscription<A> +    /// +    /// # Panics +    /// The closure provided must be a non-capturing closure. The method +    /// will panic in debug mode otherwise. +    pub fn map<F, A>(mut self, f: F) -> Subscription<A>      where          Message: 'static, +        F: Fn(Message) -> A + MaybeSend + Clone + '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 {              recipes: self                  .recipes | 
