Generics, System Parameters, and Type Erasure
Bevy’s pleasant API is powered by a conversion pipeline:
ordinary function
→ IntoSystem
→ FunctionSystem<Marker, F>
→ SystemParam tuple state
→ boxed ScheduleSystem
SystemParam uses generic associated types to distinguish long-lived parameter
state from the short-lived item borrowed for one run. Query<'w, 's, D, F> is
generic over selected data and filtering policy; D also determines whether
access is read-only.
Bundles recursively describe groups of components. Plugins are generic
composition at application construction time. Assets retain Handle<A> and
Assets<A> so an image handle cannot accidentally retrieve a mesh.
At the schedule boundary, unlike concrete function and parameter tuples must
share a collection. Bevy erases them behind dyn System, retaining virtual
operations for access metadata, initialization, running, deferred application,
and type identity.
This is the recurring pattern:
Use generics to derive exact behavior and safety; erase the final system only when heterogeneous runtime scheduling requires it.