Trait bevy::ecs::prelude::IntoSystem
source · pub trait IntoSystem<In, Out, Marker>: Sized {
type System: System<In = In, Out = Out>;
// Required method
fn into_system(this: Self) -> Self::System;
// Provided methods
fn pipe<B, Final, MarkerB>(
self,
system: B,
) -> CombinatorSystem<Pipe, Self::System, <B as IntoSystem<Out, Final, MarkerB>>::System>
where B: IntoSystem<Out, Final, MarkerB> { ... }
fn map<T, F>(self, f: F) -> AdapterSystem<F, Self::System>
where F: Send + Sync + 'static + FnMut(Out) -> T { ... }
fn system_type_id(&self) -> TypeId { ... }
}
Expand description
Required Associated Types§
Required Methods§
sourcefn into_system(this: Self) -> Self::System
fn into_system(this: Self) -> Self::System
Turns this value into its corresponding System
.
Provided Methods§
sourcefn pipe<B, Final, MarkerB>(
self,
system: B,
) -> CombinatorSystem<Pipe, Self::System, <B as IntoSystem<Out, Final, MarkerB>>::System>where
B: IntoSystem<Out, Final, MarkerB>,
fn pipe<B, Final, MarkerB>(
self,
system: B,
) -> CombinatorSystem<Pipe, Self::System, <B as IntoSystem<Out, Final, MarkerB>>::System>where
B: IntoSystem<Out, Final, MarkerB>,
Pass the output of this system A
into a second system B
, creating a new compound system.
The second system must have In<T>
as its first parameter,
where T
is the return type of the first system.
Examples found in repository?
examples/ecs/system_piping.rs (line 22)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn main() {
App::new()
.insert_resource(Message("42".to_string()))
.insert_resource(OptionalWarning(Err("Got to rusty?".to_string())))
.add_plugins(LogPlugin {
level: Level::TRACE,
filter: "".to_string(),
..default()
})
.add_systems(
Update,
(
parse_message_system.pipe(handler_system),
data_pipe_system.map(info),
parse_message_system.map(dbg),
warning_pipe_system.map(warn),
parse_error_message_system.map(error),
parse_message_system.map(drop),
),
)
.run();
}
More examples
examples/state/custom_transitions.rs (line 71)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
fn build(&self, app: &mut App) {
app.add_systems(
StateTransition,
// The internals can generate at most one transition event of specific type per frame.
// We take the latest one and clear the queue.
last_transition::<S>
// We insert the optional event into our schedule runner.
.pipe(run_reenter::<S>)
// State transitions are handled in three ordered steps, exposed as system sets.
// We can add our systems to them, which will run the corresponding schedules when they're evaluated.
// These are:
// - [`ExitSchedules`] - Ran from leaf-states to root-states,
// - [`TransitionSchedules`] - Ran in arbitrary order,
// - [`EnterSchedules`] - Ran from root-states to leaf-states.
.in_set(EnterSchedules::<S>::default()),
)
.add_systems(
StateTransition,
last_transition::<S>
.pipe(run_reexit::<S>)
.in_set(ExitSchedules::<S>::default()),
);
}
sourcefn map<T, F>(self, f: F) -> AdapterSystem<F, Self::System>
fn map<T, F>(self, f: F) -> AdapterSystem<F, Self::System>
Pass the output of this system into the passed function f
, creating a new system that
outputs the value returned from the function.
// Ignores the output of a system that may fail.
schedule.add_systems(my_system.map(drop));
fn my_system(res: Res<T>) -> Result<(), Err> {
// ...
}
Examples found in repository?
examples/ecs/system_piping.rs (line 23)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn main() {
App::new()
.insert_resource(Message("42".to_string()))
.insert_resource(OptionalWarning(Err("Got to rusty?".to_string())))
.add_plugins(LogPlugin {
level: Level::TRACE,
filter: "".to_string(),
..default()
})
.add_systems(
Update,
(
parse_message_system.pipe(handler_system),
data_pipe_system.map(info),
parse_message_system.map(dbg),
warning_pipe_system.map(warn),
parse_error_message_system.map(error),
parse_message_system.map(drop),
),
)
.run();
}
sourcefn system_type_id(&self) -> TypeId
fn system_type_id(&self) -> TypeId
Get the TypeId
of the System
produced after calling into_system
.
Object Safety§
This trait is not object safe.