Skip to content

Conversation

@regexident
Copy link
Contributor

Currently NodeMut<'a T> only exposes …

pub fn value(&mut self) -> &mut T;

… but not an equivalent immutable …

pub fn value(&self) -> &T;

This PR renames the existing name(…) to name_mut(…) and re-introduces name(…) as immutable getter.

(This is a breaking change.)

While one could assume that anyone using NodeMut will also have mutable access to it I stumbled on situations where this wasn't the case (e.g. due to wanting to abstract over NodeRef/NodeMut for mere reading) and the lack of a non-mutating node() getter made the code rather cumbersome to deal with as a consequence.

The same goes for the lack of fn children(&self) -> Children<'a, T> on NodeMut for what it's worth.

@adamreichold
Copy link
Member

I wonder if we can solve the same problem easier by letting code turn NodeMut into NodeRef directly. Something like

fn as_ref(&mut self) -> NodeRef<'_, T>;

i.e. a reborrowing operation. (Note that the lifetime of the NodeRef is shorter than that of the original NodeMut which I think is necessary for soundness.)

Otherwise, we'll just end up duplicating all of the API surface adjusted for mutability.

@regexident
Copy link
Contributor Author

That should work too, yeah!

@regexident regexident closed this by deleting the head repository May 14, 2025
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

Successfully merging this pull request may close these issues.

2 participants