-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change World::try_despawn
and World::try_insert_batch
to return Result
#17376
base: main
Are you sure you want to change the base?
Conversation
// This is effectively in an `else` block, since it can only be reached if the | ||
// above `if` fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This is effectively in an `else` block, since it can only be reached if the | |
// above `if` fails. |
/// [`World::try_despawn`]: crate::world::World::try_despawn | ||
#[derive(Error, Debug, Clone, Copy)] | ||
#[error("Could not despawn the entity with ID {0} because it {1}")] | ||
pub struct TryDespawnError(pub Entity, pub EntityDoesNotExistDetails); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Named structs instead of tuple structs please. Operations on tuple structs are much less clear, so we avoid them as a matter of style unless they're 1-element newtypes.
@@ -2332,7 +2354,7 @@ impl World { | |||
/// | |||
/// This function will panic if any of the associated entities do not exist. | |||
/// | |||
/// For the non-panicking version, see [`World::try_insert_batch`]. | |||
/// For the fallible version, see [`World::try_insert_batch`]. | |||
#[track_caller] | |||
pub fn insert_batch<I, B>(&mut self, batch: I) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to merge all of the fallible / infallible variants, but that should be done in follow-up.
Objective
Most
try
methods onWorld
return aResult
, buttry_despawn
andtry_insert_batch
don't. Since Bevy's error handling is advancing, these should be brought in line.Solution
TryDespawnError
andTryInsertBatchError
.try_despawn
,try_insert_batch
, andtry_insert_batch_if_new
now return their respective errors.try_insert_batch_with_caller
to support collecting invalid entities.Migration Guide
World::try_despawn
now returns aResult
rather than abool
.World::try_insert_batch
andWorld::try_insert_batch_if_new
now return aResult
where they previously returned nothing.