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

Support @ marker in tree! macro to append subtrees #43

Merged
merged 2 commits into from
Feb 9, 2025

Conversation

RJ
Copy link
Contributor

@RJ RJ commented Feb 5, 2025

Support merging trees in the tree! macro with the @ marker:

let subtree = tree! {
  "a" => {
    "b"
  }
};
let tree = tree! {
    "foo" => {
        "bar",
        @ subtree
    }
};
subtree:

a
└── b

tree:

foo
├── bar
└── a
    └── b

Copy link
Member

@adamreichold adamreichold left a comment

Choose a reason for hiding this comment

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

This looks good to me.

I have one tangentially related request though, could you modifiy Tree::extend_tree (backing Tree::append_subtree) to use Vec::append instead of Vec::extend for the possible gain in efficiency? Thanks!

@RJ
Copy link
Contributor Author

RJ commented Feb 9, 2025

like that?

Copy link
Member

@adamreichold adamreichold left a comment

Choose a reason for hiding this comment

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

Yes, exactly. Vec::extend likely does some specialization behind the scenes, but since our API takes ownership of the given subtree, we can use the most specialized API for that directly.

@adamreichold
Copy link
Member

Let's leave it open for a bit if anyone else wants to have a look. Otherwise, I'll merge tonight CET.

@RJ
Copy link
Contributor Author

RJ commented Feb 9, 2025

great 😃

@adamreichold adamreichold merged commit ecd16e5 into rust-scraper:master Feb 9, 2025
5 checks passed
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