Looking at code in iced I see this
enum Message {
......
ActionPerformed(text_editor::Action),
}
and
text_editor(&self.content)
.height(Fill)
.on_action(Message::ActionPerformed)
where on_action is
pub fn on_action(
mut self,
on_edit: impl Fn(Action) -> Message + 'a,
) -> Self {
self.on_edit = Some(Box::new(on_edit));
self
}
my reading of that fn is that it wants an invokable function.
The code works the same if I do
.on_action(|action| Message::ActionPerformed(action))
which is what I would expect to have to do.
I know that if x were a function (with the correct signature I could just do
.on_action(x)
but it is a surprise to be able to do it with an enum variant
Am I reading it correctly that anything that can be rendered x(y) can be used in place of a Fn requirement? Or is it special to enum?
Seems its maybe like c++ functors - if its syntactically valid to go x(y) then it can be used where a callable function would work.