Renamed members of ParamWarnPolicy
to reflect new behaviour. (#17311)
- `Once` renamed to `Warn`. - `param_warn_once()` renamed to `warn_param_missing()`. - `never_param_warn()` renamed to `ignore_param_missing()`. Also includes changes to the documentation of the above methods. Fixes #17262. ## Migration Guide - `ParamWarnPolicy::Once` has been renamed to `ParamWarnPolicy::Warn`. - `ParamWarnPolicy::param_warn_once` has been renamed to `ParamWarnPolicy::warn_param_missing`. - `ParamWarnPolicy::never_param_warn` has been renamed to `ParamWarnPolicy::ignore_param_missing`.
This commit is contained in:
parent
f5d38f30cc
commit
e808fbe987
@ -344,7 +344,7 @@ mod tests {
|
|||||||
(|mut commands: Commands| {
|
(|mut commands: Commands| {
|
||||||
commands.insert_resource(R2);
|
commands.insert_resource(R2);
|
||||||
})
|
})
|
||||||
.param_warn_once(),
|
.warn_param_missing(),
|
||||||
)
|
)
|
||||||
.chain(),
|
.chain(),
|
||||||
);
|
);
|
||||||
@ -367,20 +367,20 @@ mod tests {
|
|||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
let mut schedule = Schedule::default();
|
let mut schedule = Schedule::default();
|
||||||
schedule.set_executor_kind(executor);
|
schedule.set_executor_kind(executor);
|
||||||
schedule.configure_sets(S1.run_if((|_: Res<R1>| true).param_warn_once()));
|
schedule.configure_sets(S1.run_if((|_: Res<R1>| true).warn_param_missing()));
|
||||||
schedule.add_systems((
|
schedule.add_systems((
|
||||||
// System gets skipped if system set run conditions fail validation.
|
// System gets skipped if system set run conditions fail validation.
|
||||||
(|mut commands: Commands| {
|
(|mut commands: Commands| {
|
||||||
commands.insert_resource(R1);
|
commands.insert_resource(R1);
|
||||||
})
|
})
|
||||||
.param_warn_once()
|
.warn_param_missing()
|
||||||
.in_set(S1),
|
.in_set(S1),
|
||||||
// System gets skipped if run conditions fail validation.
|
// System gets skipped if run conditions fail validation.
|
||||||
(|mut commands: Commands| {
|
(|mut commands: Commands| {
|
||||||
commands.insert_resource(R2);
|
commands.insert_resource(R2);
|
||||||
})
|
})
|
||||||
.param_warn_once()
|
.warn_param_missing()
|
||||||
.run_if((|_: Res<R2>| true).param_warn_once()),
|
.run_if((|_: Res<R2>| true).warn_param_missing()),
|
||||||
));
|
));
|
||||||
schedule.run(&mut world);
|
schedule.run(&mut world);
|
||||||
assert!(world.get_resource::<R1>().is_none());
|
assert!(world.get_resource::<R1>().is_none());
|
||||||
|
@ -195,7 +195,7 @@ pub enum ParamWarnPolicy {
|
|||||||
/// No warning should ever be emitted.
|
/// No warning should ever be emitted.
|
||||||
Never,
|
Never,
|
||||||
/// The warning will be emitted once and status will update to [`Self::Never`].
|
/// The warning will be emitted once and status will update to [`Self::Never`].
|
||||||
Once,
|
Warn,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParamWarnPolicy {
|
impl ParamWarnPolicy {
|
||||||
@ -218,7 +218,7 @@ impl ParamWarnPolicy {
|
|||||||
name,
|
name,
|
||||||
disqualified::ShortName::of::<P>()
|
disqualified::ShortName::of::<P>()
|
||||||
),
|
),
|
||||||
Self::Once => {
|
Self::Warn => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"{0} did not run because it requested inaccessible system parameter {1}",
|
"{0} did not run because it requested inaccessible system parameter {1}",
|
||||||
name,
|
name,
|
||||||
@ -241,13 +241,13 @@ where
|
|||||||
/// Set warn policy.
|
/// Set warn policy.
|
||||||
fn with_param_warn_policy(self, warn_policy: ParamWarnPolicy) -> FunctionSystem<M, F>;
|
fn with_param_warn_policy(self, warn_policy: ParamWarnPolicy) -> FunctionSystem<M, F>;
|
||||||
|
|
||||||
/// Warn only once about invalid system parameters.
|
/// Warn and ignore systems with invalid parameters.
|
||||||
fn param_warn_once(self) -> FunctionSystem<M, F> {
|
fn warn_param_missing(self) -> FunctionSystem<M, F> {
|
||||||
self.with_param_warn_policy(ParamWarnPolicy::Once)
|
self.with_param_warn_policy(ParamWarnPolicy::Warn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable all param warnings.
|
/// Silently ignore systems with invalid parameters.
|
||||||
fn never_param_warn(self) -> FunctionSystem<M, F> {
|
fn ignore_param_missing(self) -> FunctionSystem<M, F> {
|
||||||
self.with_param_warn_policy(ParamWarnPolicy::Never)
|
self.with_param_warn_policy(ParamWarnPolicy::Never)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut world = World::default();
|
let mut world = World::default();
|
||||||
// This fails because `T` has not been added to the world yet.
|
// This fails because `T` has not been added to the world yet.
|
||||||
let result = world.run_system_once(system.param_warn_once());
|
let result = world.run_system_once(system.warn_param_missing());
|
||||||
|
|
||||||
assert!(matches!(result, Err(RunSystemError::InvalidParams(_))));
|
assert!(matches!(result, Err(RunSystemError::InvalidParams(_))));
|
||||||
}
|
}
|
||||||
|
@ -805,7 +805,7 @@ mod tests {
|
|||||||
fn system(_: Res<T>) {}
|
fn system(_: Res<T>) {}
|
||||||
|
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
let id = world.register_system(system.param_warn_once());
|
let id = world.register_system(system.warn_param_missing());
|
||||||
// This fails because `T` has not been added to the world yet.
|
// This fails because `T` has not been added to the world yet.
|
||||||
let result = world.run_system(id);
|
let result = world.run_system(id);
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ fn main() {
|
|||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
user_input.param_warn_once(),
|
user_input.warn_param_missing(),
|
||||||
move_targets.never_param_warn(),
|
move_targets.ignore_param_missing(),
|
||||||
move_pointer.never_param_warn(),
|
move_pointer.ignore_param_missing(),
|
||||||
)
|
)
|
||||||
.chain(),
|
.chain(),
|
||||||
)
|
)
|
||||||
.add_systems(Update, do_nothing_fail_validation.param_warn_once())
|
.add_systems(Update, do_nothing_fail_validation.warn_param_missing())
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user