Understanding the on_selected argument on combo_box helper function


I’m fairly new to Rust (and iced as well) and today I started to read the combo_box example and found the following argument type definition statement on the definition of the helper function combo_box:

on_selected: impl Fn(T) -> Message + 'static

This is a brand new level of Rust for me and I’m confused what exactly this means.

So on the example I mentioned this parameter receives an Enum field called Message::Selected which is defined as:

#[derive(Debug, Clone, Copy)]
enum Message {

The first thought was: Is this definition to restrict the on_selected argument to only accept Enum values?

Second question: Why exactly would you use an Enum to assign a value instead of using a regular struct ?

Third question: can on_selected argument be a closure or a regular fn function?

Fourth question: For whatever reason when I read on_selected I get the impression that this is the argument that will receive callback reference where the function will receive both a reference to the “widget” and the selected T value. Why is that not the case?

combo_box example - iced/examples/combo_box/src/main.rs at master · iced-rs/iced · GitHub
doc - combo_box in iced::widget - Rust

impl Fn(T) -> Message + 'static describes a generic type that is a static closure that takes some value of type T and returns a Message.

Message::Selected can be used as a closure. In fact, it can be equivalent to writing: |language| Message::Selected(language).

on_selected basically is a closure that turns an element of the combo_box into a Message. This Message is fed to Application::update when the user selects something in the combo_box.