Skip to content

datastore: make Objects methods exhaustive#151

Merged
teh-cmc merged 2 commits intomainfrom
fix/objects_silent_drops
Oct 3, 2022
Merged

datastore: make Objects methods exhaustive#151
teh-cmc merged 2 commits intomainfrom
fix/objects_silent_drops

Conversation

@teh-cmc
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

@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.


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

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
Copy Markdown
Contributor 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
Copy Markdown
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