Rust Iced container theming issue (Rust Compiler question)

Hi Guys,

Using Iced I am trying to build a small demo app; but I have a strange issue styling a container.

Here is my code:

        let f = |theme: &Theme| -> container::Appearance {
            let palette = theme.extended_palette();
    
            container::Appearance {
                text_color: Some(palette.background.strong.text),
                background: Some(palette.background.strong.color.into()),
                ..Default::default()
            }
        };
        let c = Container::from(f);
        let top = container(row![
            button("Demo A").padding(10),
            button("Demo B").padding(10)
        ].padding(20).spacing(40)).style(c);

Compiler error:

 --> src/main.rs:51:33
   |
51 |         let c = Container::from(f);
   |                 --------------- ^ the trait `From<[closure@src/main.rs:42:17: 42:57]>` is not implemented for `Container`
   |                 |
   |                 required by a bound introduced by this call
   |
   = help: the trait `From<for<'a> fn(&'a Theme) -> iced::widget::container::Appearance>` is implemented for `Container`

Could you help me what I am missing?

Ok. So something strange with the compiler. If I coerce type it works:

let c = Container::from(f as for<'r> fn(&'r _) -> _);

But why is this strange compiler behavior?

Related discord discussion:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.