-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Revert one-to-one relationships #18817
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
Conversation
|
This can still be implemented easily by the user by newtyping A panicking version: impl RelationshipSourceCollection for MyNewtyped(Entity) {
type SourceIter<'a> = core::option::IntoIter<Entity>;
fn new() -> Self {
MyNewtyped(Entity::PLACEHOLDER)
}
fn reserve(&mut self, _: usize) {}
fn with_capacity(_capacity: usize) -> Self {
MyNewtyped(Self::new())
}
fn add(&mut self, entity: Entity) -> bool {
assert_eq!(self.0, Entity::PLACEHOLDER, "remove the original relationship first");
self.0 = entity;
true
}
fn remove(&mut self, entity: Entity) -> bool {
if self.0 == entity {
self.0 = Entity::PLACEHOLDER;
return true;
}
false
}
fn iter(&self) -> Self::SourceIter<'_> {
if self.0 == Entity::PLACEHOLDER {
None.into_iter()
} else {
Some(self.0).into_iter()
}
}
fn len(&self) -> usize {
if self.0 == Entity::PLACEHOLDER {
return 0;
}
1
}
fn clear(&mut self) {
self.0 = Entity::PLACEHOLDER;
}
fn shrink_to_fit(&mut self) {}
fn extend_from_iter(&mut self, entities: impl IntoIterator<Item = Entity>) {
if let Some(entity) = entities.into_iter().last() {
assert_eq!(self.0, Entity::PLACEHOLDER, "remove the original relationship first");
self.0 = entity;
}
}
}A proper fix here would be if |
|
Good call! I do prefer panicking over fully removing the API. The newtype isn't necessary though! Just put out a PR. |
|
closed in favour of #18833 |
# Objective One to one relationships (added in #18087) can currently easily be invalidated by having two entities relate to the same target. Alternative to #18817 (removing one-to-one relationships) ## Solution Panic if a RelationshipTarget is already targeted. Thanks @urben1680 for the idea! --------- Co-authored-by: François Mockers <[email protected]>
# Objective One to one relationships (added in #18087) can currently easily be invalidated by having two entities relate to the same target. Alternative to #18817 (removing one-to-one relationships) ## Solution Panic if a RelationshipTarget is already targeted. Thanks @urben1680 for the idea! --------- Co-authored-by: François Mockers <[email protected]>
# Objective One to one relationships (added in bevyengine#18087) can currently easily be invalidated by having two entities relate to the same target. Alternative to bevyengine#18817 (removing one-to-one relationships) ## Solution Panic if a RelationshipTarget is already targeted. Thanks @urben1680 for the idea! --------- Co-authored-by: François Mockers <[email protected]>
Objective
One to one relationships (added in #18087) can currently easily be invalidated by having two entities relate to the same target:
Solution
Revert one-to-one relationships. We can re-add them in the future if the impl properly takes this case into account.