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

MutHierarchies are unsound #79

Open
douweschulte opened this issue Jan 25, 2022 · 1 comment
Open

MutHierarchies are unsound #79

douweschulte opened this issue Jan 25, 2022 · 1 comment

Comments

@douweschulte
Copy link
Owner

douweschulte commented Jan 25, 2022

If you create a hierarchy you could potentially delete the selected lower levels from a higher level. For example you select (Model(0), Chain("A"), Residue(123), Conformer("ALA"), Atom("CA", 450, "C")) and then use chain.remove_atoms_by(|a| a.element() == "C") this would delete the selected atom, and would cause undefined behaviour when the atom is used afterwards.

The proposal is to create a trait with all safe functions for each level and make the levels implement it. The hierarchies can then return a trait object instead of the struct which would limit the use of the unsound functions. The unsound functions are all deleting functions and adding/inserting has to be checked thoroughly for potential issues. Any function that returns mut references to lower levels in the hierarchy also has to have a safe counterpart returning a Trait object.

Unsound:

  • Methods removing items below
  • Methods returning a &mut to an item in any level below?
  • Sort?
  • Extend (and join)?
  • Add lower level item? (what if this triggers a reallocation of the inner Vec?)
@douweschulte
Copy link
Owner Author

It might be solved with the use on Pin

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

No branches or pull requests

1 participant