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

datastore: make Objects methods exhaustive #151

Merged
merged 2 commits into from
Oct 3, 2022
Merged

Conversation

teh-cmc
Copy link
Member

@teh-cmc teh-cmc commented Oct 3, 2022

Objects currently has some implicit invariants that can potentially lead to data being silently dropped if you're not aware of them.

This PR makes sure to check those invariants at compile time.

@teh-cmc teh-cmc requested a review from emilk October 3, 2022 18:09
Copy link
Member

@jleibs jleibs left a comment

Choose a reason for hiding this comment

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

This seems reasonable/correct to me.

@@ -623,7 +623,30 @@ impl<'s> Objects<'s> {
}

pub fn is_empty(&self) -> bool {
self.space.is_empty() && !self.has_any_2d() && !self.has_any_3d()
let Self {
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure I understand the intent: by destructing Self into it's fields we ensure that if somebody adds to to the Objects struct they will also have to change this line of code and will be more likely to add the necessary support?

Copy link
Member Author

@teh-cmc teh-cmc Oct 3, 2022

Choose a reason for hiding this comment

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

Exactly!

Props to @emilk, I had completely forgotten about that trick 🙃

Copy link
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

wonderful!

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.

3 participants