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.
SystemParamBuilder::build
correctly registers allWorld
accesses used bySystemParam::get_param
with the providedsystem_meta
.- None of the world accesses may conflict with any prior accesses registered
on
system_meta
.
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§
Sourcefn build(self, world: &mut World, meta: &mut SystemMeta) -> P::State
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§
Sourcefn build_state(self, world: &mut World) -> SystemState<P>
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 ()
impl SystemParamBuilder<()> for ()
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ₙ)
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.