@@ -14,14 +14,14 @@ use bevy_ecs::{
1414/// #[derive(Event)]
1515/// pub struct MyEvent; // Custom event type.
1616/// fn my_system(mut writer: EventWriter<MyEvent>) {
17- /// writer.send (MyEvent);
17+ /// writer.write (MyEvent);
1818/// }
1919///
2020/// # bevy_ecs::system::assert_is_system(my_system);
2121/// ```
2222/// # Observers
2323///
24- /// "Buffered" Events, such as those sent directly in [`Events`] or sent using [`EventWriter`], do _not_ automatically
24+ /// "Buffered" Events, such as those sent directly in [`Events`] or written using [`EventWriter`], do _not_ automatically
2525/// trigger any [`Observer`]s watching for that event, as each [`Event`] has different requirements regarding _if_ it will
2626/// be triggered, and if so, _when_ it will be triggered in the schedule.
2727///
@@ -32,7 +32,7 @@ use bevy_ecs::{
3232///
3333/// # Untyped events
3434///
35- /// `EventWriter` can only send events of one specific type, which must be known at compile-time.
35+ /// `EventWriter` can only write events of one specific type, which must be known at compile-time.
3636/// This is not a problem most of the time, but you may find a situation where you cannot know
3737/// ahead of time every kind of event you'll need to send. In this case, you can use the "type-erased event" pattern.
3838///
@@ -64,34 +64,71 @@ pub struct EventWriter<'w, E: Event> {
6464}
6565
6666impl < ' w , E : Event > EventWriter < ' w , E > {
67+ /// Writes an `event`, which can later be read by [`EventReader`](super::EventReader)s.
68+ /// This method returns the [ID](`EventId`) of the written `event`.
69+ ///
70+ /// See [`Events`] for details.
71+ #[ doc( alias = "send" ) ]
72+ #[ track_caller]
73+ pub fn write ( & mut self , event : E ) -> EventId < E > {
74+ self . events . send ( event)
75+ }
76+
77+ /// Sends a list of `events` all at once, which can later be read by [`EventReader`](super::EventReader)s.
78+ /// This is more efficient than sending each event individually.
79+ /// This method returns the [IDs](`EventId`) of the written `events`.
80+ ///
81+ /// See [`Events`] for details.
82+ #[ doc( alias = "send_batch" ) ]
83+ #[ track_caller]
84+ pub fn write_batch ( & mut self , events : impl IntoIterator < Item = E > ) -> SendBatchIds < E > {
85+ self . events . send_batch ( events)
86+ }
87+
88+ /// Writes the default value of the event. Useful when the event is an empty struct.
89+ /// This method returns the [ID](`EventId`) of the written `event`.
90+ ///
91+ /// See [`Events`] for details.
92+ #[ doc( alias = "send_default" ) ]
93+ #[ track_caller]
94+ pub fn write_default ( & mut self ) -> EventId < E >
95+ where
96+ E : Default ,
97+ {
98+ self . events . send_default ( )
99+ }
100+
67101 /// Sends an `event`, which can later be read by [`EventReader`](super::EventReader)s.
68102 /// This method returns the [ID](`EventId`) of the sent `event`.
69103 ///
70104 /// See [`Events`] for details.
105+ #[ deprecated( since = "0.16.0" , note = "Use `EventWriter::write` instead." ) ]
71106 #[ track_caller]
72107 pub fn send ( & mut self , event : E ) -> EventId < E > {
73- self . events . send ( event)
108+ self . write ( event)
74109 }
75110
76111 /// Sends a list of `events` all at once, which can later be read by [`EventReader`](super::EventReader)s.
77112 /// This is more efficient than sending each event individually.
78113 /// This method returns the [IDs](`EventId`) of the sent `events`.
79114 ///
80115 /// See [`Events`] for details.
116+ #[ deprecated( since = "0.16.0" , note = "Use `EventWriter::write_batch` instead." ) ]
81117 #[ track_caller]
82118 pub fn send_batch ( & mut self , events : impl IntoIterator < Item = E > ) -> SendBatchIds < E > {
83- self . events . send_batch ( events)
119+ self . write_batch ( events)
84120 }
85121
86122 /// Sends the default value of the event. Useful when the event is an empty struct.
87123 /// This method returns the [ID](`EventId`) of the sent `event`.
88124 ///
89125 /// See [`Events`] for details.
126+ #[ deprecated( since = "0.16.0" , note = "Use `EventWriter::write_default` instead." ) ]
90127 #[ track_caller]
91128 pub fn send_default ( & mut self ) -> EventId < E >
92129 where
93130 E : Default ,
94131 {
95- self . events . send_default ( )
132+ self . write_default ( )
96133 }
97134}
0 commit comments