From ffc3c64621d31a0ff5de97c2b95c328480501d24 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Thu, 8 Aug 2024 12:48:33 -0700 Subject: [PATCH] Add second "contextless" example --- crates/bevy_ecs/src/observer/mod.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/observer/mod.rs b/crates/bevy_ecs/src/observer/mod.rs index 5c0b0a7ed4cfa..8e4faebf761b8 100644 --- a/crates/bevy_ecs/src/observer/mod.rs +++ b/crates/bevy_ecs/src/observer/mod.rs @@ -445,7 +445,7 @@ impl World { /// #[derive(Event, Clone, Debug)] /// struct Foo(usize); /// -/// #[derive(Event, Debug)] +/// #[derive(Event, Clone, Debug)] /// struct Bar(bool); /// /// #[derive(Event, Debug)] @@ -460,6 +460,29 @@ impl World { /// println!("Combined Event: {:?}", trigger.event()); /// }); /// ``` +/// +/// ``` +/// # use bevy_ecs::prelude::*; +/// # use bevy_ecs::observer::trigger_map; +/// # let mut world = World::new(); +/// +/// #[derive(Event, Clone, Debug)] +/// struct Foo(usize); +/// +/// #[derive(Event, Clone, Debug)] +/// struct Bar(bool); +/// +/// // If you don't care about capturing the original event context, +/// // you can just use a unit struct. +/// #[derive(Event, Debug)] +/// struct Combined; +/// +/// world.observe(trigger_map(|event: Foo| Combined)); +/// world.observe(trigger_map(|event: Bar| Combined)); +/// world.observe(|trigger: Trigger| { +/// println!("Combined Event"); +/// }); +/// ``` pub fn trigger_map U + Send + Sync + 'static>( map: F, ) -> impl ObserverSystem {