Skip to content
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

Add TileStorage::drain and return removed entities in remove #586

Merged
merged 4 commits into from
Dec 23, 2024

Conversation

rparrett
Copy link
Collaborator

Fixes #579

I was tempted to call this remove_all instead to remove a potential source of confusion about what is happening to the underlying storage. Still on the fence about this, so let me know what you think.

src/tiles/storage.rs Outdated Show resolved Hide resolved
Co-authored-by: Rob Parrett <[email protected]>
///
/// Panics if the given `tile_pos` doesn't lie within the extents of the underlying tile map.
pub fn remove(&mut self, tile_pos: &TilePos) {
self.tiles[tile_pos.to_index(&self.size)].take();
pub fn remove(&mut self, tile_pos: &TilePos) -> Option<Entity> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we get rid of this entirely and make checked_remove the new remove while we're adding a return value? 0.16 is going to come with fallible systems too, and I can't actually think of a use case for panicking here. Its not chainable, so .unwrap() won't add length to chains of calls if panicing is preferred.

upstream preference seems to be for returned errors, especially in cases of lesser-used apis.

Copy link
Collaborator Author

@rparrett rparrett Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

The whole set of methods could really use a closer look though. Maybe I should revert the remove changes and we can discuss in a separate issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to revert, but happy to discuss more generally in a separate issue. Even if we do that sort of thing the function signatures here will match and the only difference will be "no panic".

@ChristopherBiscardi ChristopherBiscardi merged commit e5319b1 into StarArawn:main Dec 23, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding drain method to TileStorage
2 participants