Fix stacked borrows violations by implementing 'Yoda notation' pattern #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the stacked borrows violations reported in issue #1 by implementing the suggested "Yoda notation" pattern. The core issue was that the
Storestruct was creating overlapping mutable borrows when calling tree methods on its own memory.Problem Analysis
The original error occurred because:
Storestruct owns both the memory (mem_ptr) and the tree objects (sources,targets)self.sources.attach(&mut *root, index), this creates:self.sourcesself(viaroot)Solution
Implemented the "Yoda notation" approach as suggested in the issue:
attach_with_mem()anddetach_with_mem()to theLinksTreetraitattach_source_unchecked(),detach_source_unchecked(), etc. to pass memory explicitlyKey Changes
src/mem/traits.rs: ExtendedLinksTreetrait with memory-explicit methodssrc/mem/unit/store.rs: Modified Store to use new methods with explicit memory passingTesting
While the project dependencies currently have compilation issues unrelated to this fix, the core approach follows the exact pattern recommended in the issue to resolve stacked borrows violations.
The fix ensures that:
selfFixes #1
🤖 Generated with Claude Code