iced icon indicating copy to clipboard operation
iced copied to clipboard

New BootFn abstraction can't work with owned state since it's only implemented for Fn() (and not FnOnce())

Open udoprog opened this issue 2 months ago • 1 comments

Is your issue REALLY a bug?

  • [x] My issue is indeed a bug!
  • [x] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • [x] I have searched the existing issues.

Is this issue related to iced?

  • [x] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

This seems to be a regression in features.

With the new BootFn abstraction, you are expected to provide a boot function as the first argument to iced::application:

iced::application(|| /* build application */, .., ..)

This replaces the old mechanism of run_with.

However, since the boot fn is only implemented for Fn, it can no longer be used for owned state passed into the application:

error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
   --> src/lib.rs:178:9
    |
177 |     iced::application(
    |     ----------------- required by a bound introduced by this call
178 |         || Application::new(service),
    |         ^^--------------------------
    |         |                   |
    |         |                   closure is `FnOnce` because it moves the variable `service` out of its environment
    |         this closure implements `FnOnce`, not `Fn`
    |         the requirement to implement `Fn` derives from here
    |
    = note: required for `{closure@src/lib.rs:178:9: 178:11}` to implement `BootFn<application::Application, application::Message>`

This is a bit of an issue when the state being passed into the application is difficult to clone or expensive to set up which is the case for the application I'm migrating.

What is the expected behavior?

That BootFn is implemented for FnOnce or something else allowing a similar mechanism as run_with to be used.

Version

master

Operating System

Linux

Do you have any log output?


udoprog avatar Oct 14 '25 14:10 udoprog

see https://discourse.iced.rs/t/solved-new-boot-trait-no-longer-able-to-use-a-capturing-closure-to-initialize-application-state

edwloef avatar Oct 14 '25 14:10 edwloef

Migrated to 0.14 and ran into this issue as well. Would be good to have that BootFn trait bound on FnOnce instead of Fn. The workarounds are not ideal.

darrell-roberts avatar Dec 18 '25 20:12 darrell-roberts