Skip to content

Commit 0747b66

Browse files
authored
ReadOnlySystem diagnostics and type alias (#19138)
# Objective - Improve usability of read-only systems. ## Solution - Added `on_unimplemented` diagnostics for types/functions that aren't read-only systems. - Added `BoxedReadOnlySystem` type alias, similar to `BoxedSystem`. ## Testing Can/should we test these diagnostics?
1 parent 3caca42 commit 0747b66

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crates/bevy_ecs/src/system/system.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ pub trait System: Send + Sync + 'static {
221221
///
222222
/// This must only be implemented for system types which do not mutate the `World`
223223
/// when [`System::run_unsafe`] is called.
224+
#[diagnostic::on_unimplemented(
225+
message = "`{Self}` is not a read-only system",
226+
label = "invalid read-only system"
227+
)]
224228
pub unsafe trait ReadOnlySystem: System {
225229
/// Runs this system with the given input in the world.
226230
///
@@ -245,6 +249,9 @@ pub unsafe trait ReadOnlySystem: System {
245249
/// A convenience type alias for a boxed [`System`] trait object.
246250
pub type BoxedSystem<In = (), Out = ()> = Box<dyn System<In = In, Out = Out>>;
247251

252+
/// A convenience type alias for a boxed [`ReadOnlySystem`] trait object.
253+
pub type BoxedReadOnlySystem<In = (), Out = ()> = Box<dyn ReadOnlySystem<In = In, Out = Out>>;
254+
248255
pub(crate) fn check_system_change_tick(
249256
last_run: &mut Tick,
250257
check: CheckChangeTicks,

0 commit comments

Comments
 (0)