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

Implement mutable visits #9

Merged
merged 2 commits into from
Sep 5, 2022

Conversation

lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Sep 4, 2022

This PR implements two new traits: VisitorMut and DriveMut. It allows mutating the data structure that is being visited.

Here is an example of what is now possible :

#[derive(DriveMut)]
struct Chain {
    next: Option<Box<Chain>>,
}

#[derive(VisitorMut)]
#[visitor(Chain(enter))]
struct ChainCutter {
    cut_at_depth: usize,
}

impl ChainCutter {
    fn enter_chain(&mut self, item: &mut Chain) {
        if self.cut_at_depth == 0 {
            item.next = None;
        } else {
            self.cut_at_depth -= 1;
        }
    }
}

Closes #8

Copy link
Owner

@nikis05 nikis05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice addition, thanks for your contribution!

@nikis05 nikis05 merged commit 360d448 into nikis05:master Sep 5, 2022
@lovasoa lovasoa deleted the issue8-implement-mutable-visit branch September 5, 2022 16:25
@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 5, 2022

Great, thanks for merging !

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.

Mutable visiting
2 participants