bevy_ecs::system

Trait SystemParamBuilder

Source
pub unsafe trait SystemParamBuilder<P: SystemParam>: Sized {
    // Required method
    fn build(self, world: &mut World, meta: &mut SystemMeta) -> P::State;

    // Provided method
    fn build_state(self, world: &mut World) -> SystemState<P> { ... }
}
Expand description

A builder that can create a SystemParam.

fn some_system(param: MyParam) {}

fn build_system(builder: impl SystemParamBuilder<MyParam>) {
    let mut world = World::new();
    // To build a system, create a tuple of `SystemParamBuilder`s
    // with a builder for each parameter.
    // Note that the builder for a system must be a tuple,
    // even if there is only one parameter.
    (builder,)
        .build_state(&mut world)
        .build_system(some_system);
}

fn build_closure_system_infer(builder: impl SystemParamBuilder<MyParam>) {
    let mut world = World::new();
    // Closures can be used in addition to named functions.
    // If a closure is used, the parameter types must all be inferred
    // from the builders, so you cannot use plain `ParamBuilder`.
    (builder, ParamBuilder::resource())
        .build_state(&mut world)
        .build_system(|param, res| {
            let param: MyParam = param;
            let res: Res<R> = res;
        });
}

fn build_closure_system_explicit(builder: impl SystemParamBuilder<MyParam>) {
    let mut world = World::new();
    // Alternately, you can provide all types in the closure
    // parameter list and call `build_any_system()`.
    (builder, ParamBuilder)
        .build_state(&mut world)
        .build_any_system(|param: MyParam, res: Res<R>| {});
}

See the documentation for individual builders for more examples.

§List of Builders

ParamBuilder can be used for parameters that don’t require any special building. Using a ParamBuilder will build the system parameter the same way it would be initialized in an ordinary system.

ParamBuilder also provides factory methods that return a ParamBuilder typed as impl SystemParamBuilder<P> for common system parameters that can be used to guide closure parameter inference.

QueryParamBuilder can build a Query to add additional filters, or to configure the components available to FilteredEntityRef or FilteredEntityMut. You can also use a QueryState to build a Query.

LocalBuilder can build a Local to supply the initial value for the Local.

FilteredResourcesParamBuilder can build a FilteredResources, and FilteredResourcesMutParamBuilder can build a FilteredResourcesMut, to configure the resources that can be accessed.

DynParamBuilder can build a DynSystemParam to determine the type of the inner parameter, and to supply any SystemParamBuilder it needs.

Tuples of builders can build tuples of parameters, one builder for each element. Note that since systems require a tuple as a parameter, the outer builder for a system will always be a tuple.

A Vec of builders can build a Vec of parameters, one builder for each element.

A ParamSetBuilder can build a ParamSet. This can wrap either a tuple or a Vec, one builder for each element.

A custom system param created with #[derive(SystemParam)] can be buildable if it includes a #[system_param(builder)] attribute. See the documentation for SystemParam derives.

§Safety

The implementor must ensure the following is true.

Note that this depends on the implementation of SystemParam::get_param, so if Self is not a local type then you must call SystemParam::init_state or another SystemParamBuilder::build

Required Methods§

Source

fn build(self, world: &mut World, meta: &mut SystemMeta) -> P::State

Registers any World access used by this SystemParam and creates a new instance of this param’s State.

Provided Methods§

Source

fn build_state(self, world: &mut World) -> SystemState<P>

Create a SystemState from a SystemParamBuilder. To create a system, call SystemState::build_system on the result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SystemParamBuilder<()> for ()

Source§

fn build( self, _world: &mut World, _meta: &mut SystemMeta, ) -> <() as SystemParam>::State

Source§

impl<P: SystemParam, B: SystemParamBuilder<P>> SystemParamBuilder<(P₁, P₂, …, Pₙ)> for (B₁, B₂, …, Bₙ)

This trait is implemented for tuples up to 17 items long.

Source§

fn build( self, _world: &mut World, _meta: &mut SystemMeta, ) -> <(P,) as SystemParam>::State

Source§

impl<P: SystemParam, B: SystemParamBuilder<P>> SystemParamBuilder<Vec<P>> for Vec<B>

Source§

fn build( self, world: &mut World, meta: &mut SystemMeta, ) -> <Vec<P> as SystemParam>::State

Implementors§

Source§

impl<'a, 'w, 's> SystemParamBuilder<DynSystemParam<'w, 's>> for DynParamBuilder<'a>

Source§

impl<'s, T: FromWorld + Send + 'static> SystemParamBuilder<Local<'s, T>> for LocalBuilder<T>

Source§

impl<'w, 's, D: QueryData + 'static, F: QueryFilter + 'static> SystemParamBuilder<Query<'w, 's, D, F>> for QueryState<D, F>

Source§

impl<'w, 's, D: QueryData + 'static, F: QueryFilter + 'static, T: FnOnce(&mut QueryBuilder<'_, D, F>)> SystemParamBuilder<Query<'w, 's, D, F>> for QueryParamBuilder<T>

Source§

impl<'w, 's, P0: SystemParam, B0: SystemParamBuilder<P0>> SystemParamBuilder<ParamSet<'w, 's, (P0,)>> for ParamSetBuilder<(B0,)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1)>> for ParamSetBuilder<(B0, B1)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2)>> for ParamSetBuilder<(B0, B1, B2)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>, B3: SystemParamBuilder<P3>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2, P3)>> for ParamSetBuilder<(B0, B1, B2, B3)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>, B3: SystemParamBuilder<P3>, B4: SystemParamBuilder<P4>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2, P3, P4)>> for ParamSetBuilder<(B0, B1, B2, B3, B4)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>, B3: SystemParamBuilder<P3>, B4: SystemParamBuilder<P4>, B5: SystemParamBuilder<P5>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2, P3, P4, P5)>> for ParamSetBuilder<(B0, B1, B2, B3, B4, B5)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam, P6: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>, B3: SystemParamBuilder<P3>, B4: SystemParamBuilder<P4>, B5: SystemParamBuilder<P5>, B6: SystemParamBuilder<P6>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2, P3, P4, P5, P6)>> for ParamSetBuilder<(B0, B1, B2, B3, B4, B5, B6)>

Source§

impl<'w, 's, P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam, P6: SystemParam, P7: SystemParam, B0: SystemParamBuilder<P0>, B1: SystemParamBuilder<P1>, B2: SystemParamBuilder<P2>, B3: SystemParamBuilder<P3>, B4: SystemParamBuilder<P4>, B5: SystemParamBuilder<P5>, B6: SystemParamBuilder<P6>, B7: SystemParamBuilder<P7>> SystemParamBuilder<ParamSet<'w, 's, (P0, P1, P2, P3, P4, P5, P6, P7)>> for ParamSetBuilder<(B0, B1, B2, B3, B4, B5, B6, B7)>

Source§

impl<'w, 's, P: SystemParam, B: SystemParamBuilder<P>> SystemParamBuilder<ParamSet<'w, 's, Vec<P>>> for ParamSetBuilder<Vec<B>>

Source§

impl<'w, 's, T: FnOnce(&mut FilteredResourcesBuilder<'_>)> SystemParamBuilder<FilteredResources<'w, 's>> for FilteredResourcesParamBuilder<T>

Source§

impl<'w, 's, T: FnOnce(&mut FilteredResourcesMutBuilder<'_>)> SystemParamBuilder<FilteredResourcesMut<'w, 's>> for FilteredResourcesMutParamBuilder<T>

Source§

impl<P: SystemParam> SystemParamBuilder<P> for ParamBuilder