diff --git a/src/dialog/file_chooser/mod.rs b/src/dialog/file_chooser/mod.rs index 1305ea6b..ccb15c42 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() {