Returning Parts of a Mutable Borrow Triggers the Borrow Checker

⚓ Rust    📅 2025-07-17    👤 surdeus    👁️ 3      

surdeus

Hey all!
I'm currently working on an swc plugin which replaces parts of a JavaScript DOM.
I came to realize that working with swcs complex data structures involving nested Boxes and enums which must be matched against is quite cumbersome when it comes to borrow checking.

This is an excert of my method which parses a node and, in case it's not a nameof expression, returns None and otherwise returns an Err (possibly holding immutable parts of the node) or an Ok (holding mutable parts of the node):

Rust Playground

Sadly, I can't find myself able to find a way to work around the error reported in this code snippet.
Could you help me understand what I'm doing wrong or how I can improve this piece of code?

Best regards

6 posts - 4 participants

Read full topic

🏷️ rust_feed