WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

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

@udoprog

Description

@udoprog

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • 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?

  • I have searched the existing issues.

Is this issue related to iced?

  • 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions