bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Make `SystemSet` marker traits mutually exclusive

Open joseph-gio opened this issue 2 years ago • 0 comments

Objective

Fix an issue discussed in #7882. The problem comes down to the fact that BaseSystemSet and FreeSystemSet can both be implemented for the same type, which opens the door for misuse and results in actively harmful error messages.

Solution

Use an associated type to determine whether a system set is base or not. Add blanket implementations to the marker traits based on the value of the associated type. Users are disallowed from manually implementing either marker trait due to blanket implementations, which ensures that the two traits are disjoint.


Migration Guide

The marker traits BaseSystemSet and FreeSystemSet can no longer be implemented manually. Instead, implement KindedSystemSet:

use bevy_ecs::schedule;

// Before:
impl schedule::BaseSystemSet for MySet {}

// After:
impl schedule::KindedSystemSet for MySet {
    // This will automatically implement `BaseSystemSet` for `MySet` due to a blanket implementation.
    type Kind = schedule::BaseSystemSetMarker;
}

joseph-gio avatar Mar 10 '23 23:03 joseph-gio