-
-
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
Make EntityMapper fallible #17197
base: main
Are you sure you want to change the base?
Make EntityMapper fallible #17197
Conversation
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.
After thinking about it a bit more, I think we always should replace the entity with Entity::PLACEHOLDER
instead of keeping it untouched.
If yes, do we need to return Option
?
So you're saying that you update
I think that works but it requires a bit of user-knowledge. It's kind of 'hidden' pattern that the user can remember to use Entity::PLACEHOLDER as an error value in both |
No, I suggesting to always assign the entity even if it's fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
self.entity = entity_mapper.map_entity(self.entity);
} It's just better then pointing to some random entity. So I suggesting to edit the |
Ah I see; yes this works for my usecase! |
Objective
Solution
Update the
EntityMapper
trait so thatmap_entity(&mut self, entity: Entity)
returns anOption<Entity>
instead ofEntity
to account for cases where the mapping fails or cannot be done.Testing
Updated the unit tests.
Maybe we should be using a Result, but I didn't know what to put in the error type. Maybe
Box<dyn Error>
?Migration Guide
map_entity
method of theEntityMapper
trait now returns anOption<Entity>
instead of anEntity
to support cases where the mapping fails. You will probably need to update any custom implementations of theMapEntities
trait.