diff --git a/core/src/element.rs b/core/src/element.rs index a8c0d6adec..70c94a7563 100644 --- a/core/src/element.rs +++ b/core/src/element.rs @@ -334,7 +334,7 @@ where viewport, ); - shell.merge(local_shell, &self.mapper); + shell.merge(local_shell, |m| Some((self.mapper)(m))); } fn draw( diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs index d6db752679..1fbaebfcdd 100644 --- a/core/src/overlay/element.rs +++ b/core/src/overlay/element.rs @@ -90,7 +90,7 @@ where self.content .update(event, layout, cursor, renderer, &mut local_shell); - shell.merge(local_shell, self.mapper); + shell.merge(local_shell, |m| Some((self.mapper)(m))); } fn mouse_interaction( diff --git a/core/src/shell.rs b/core/src/shell.rs index ef1b369ace..d57a061aa2 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -211,13 +211,13 @@ impl<'a, Message> Shell<'a, Message> { /// function to the messages of the latter. /// /// This method is useful for composition. - pub fn merge(&mut self, mut other: Shell<'_, B>, f: impl Fn(B) -> Message) { + pub fn merge(&mut self, mut other: Shell<'_, B>, f: impl Fn(B) -> Option) { self.bus.messages.extend( other .bus .messages .drain(..) - .map(|(message, receipt)| (f(message), receipt)), + .filter_map(|(message, receipt)| Some((f(message)?, receipt))), ); self.is_layout_invalid = match (self.is_layout_invalid, other.is_layout_invalid) { diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index f54d42da18..cc7fc1f7b4 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -524,7 +524,7 @@ mod toast { instant.take(); } - shell.merge(local_shell, std::convert::identity); + shell.merge(local_shell, Some); } }