From 9904f0ba13cc5c5d4395bbb7a1f2495abc655636 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 13 Nov 2023 14:34:35 +0100 Subject: [PATCH] improv(file_chooser): make subscription handler a generic closure --- src/dialog/file_chooser/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dialog/file_chooser/mod.rs b/src/dialog/file_chooser/mod.rs index 1305ea6baba..ccb15c420dd 100644 --- a/src/dialog/file_chooser/mod.rs +++ b/src/dialog/file_chooser/mod.rs @@ -44,8 +44,12 @@ pub fn save_file() -> Option { } /// Creates a subscription for file chooser events. -pub fn subscription(handle: fn(Message) -> M) -> Subscription { - let type_id = std::any::TypeId::of::>(); +pub fn subscription(handle: H) -> Subscription +where + M: Send + 'static, + H: Fn(Message) -> M + Send + Sync + 'static, +{ + let type_id = std::any::TypeId::of::>(); iced::subscription::channel(type_id, 1, move |output| async move { let mut state = Handler { @@ -156,13 +160,13 @@ impl Sender { } } -struct Handler { +struct Handler M> { active: Option>, - handle: fn(Message) -> M, + handle: Handle, output: channel::mpsc::Sender, } -impl Handler { +impl M> Handler { /// Emits close request if there is an active dialog request. async fn close(&mut self) { if let Some(request) = self.active.take() {