I have a struct with a generic lifetime parameter that defines my app. In the main function, when I try to call iced::application
and pass in the update and view methods on that struct, I receive a flurry of errors (output included below).
Here is the struct in question:
pub(super) struct App<'a> {
welcome_screen: welcome::Welcome,
main_screen: view::View<'a>,
curr_screen: Screen,
version: crate::Version
}
And the main function:
fn main() -> iced::Result {
iced::application("Test App", app::App::update, app::App::view)
.exit_on_close_request(false)
.decorations(false)
.subscription(app::App::subscription)
.antialiasing(true)
.run_with(|| app::App::new(VERSION))
}
I think that it is because the update method has a generic lifetime 'a, which is necessary because the main screen requires a lifetime parameter. Here is the signature:
impl<'a> App<'a> {
...
pub fn update(&'a mut self, message: Message) -> impl Into<Task<Message>> {
...
}
}
Is there something I’m missing that would let me have the App struct contain a generic lifetime?
The error messages:
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | iced::application("Test App", app::App::update, app::App::view)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | iced::application("Test App", app::App::update, app::App::view)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
| |_____________________________________^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
| |_____________________________________^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
| |___________________________^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
| |___________________________^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
| |_____________________________________________^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
| |_____________________________________________^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
49 | | .antialiasing(true)
| |___________________________^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
49 | | .antialiasing(true)
| |___________________________^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `FnOnce` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
49 | | .antialiasing(true)
50 | | .run_with(|| app::App::new(VERSION))
| |____________________________________________^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `FnOnce<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`
error: implementation of `std::ops::Fn` is not general enough
--> src/main.rs:45:5
|
45 | / iced::application("Test App", app::App::update, app::App::view)
46 | | .exit_on_close_request(false)
47 | | .decorations(false)
48 | | .subscription(app::App::subscription)
49 | | .antialiasing(true)
50 | | .run_with(|| app::App::new(VERSION))
| |____________________________________________^ implementation of `std::ops::Fn` is not general enough
|
= note: `fn(&'2 mut App<'2>, app::Message) -> impl Into<Task<app::Message>> {App::<'2>::update}` must implement `std::ops::Fn<(&'1 mut App<'_>, app::Message)>`, for any lifetime `'1`...
= note: ...but it actually implements `std::ops::Fn<(&'2 mut App<'2>, app::Message)>`, for some specific lifetime `'2`