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

Rename method fn value() on NodeMut<…> to value_mut(), re-introducing the former as an immutable getter #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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!

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