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

Allow manipulating attributes while iterating over them #158

Open
Fxxxlei opened this issue Feb 8, 2023 · 1 comment
Open

Allow manipulating attributes while iterating over them #158

Fxxxlei opened this issue Feb 8, 2023 · 1 comment

Comments

@Fxxxlei
Copy link

Fxxxlei commented Feb 8, 2023

I would like to have a function similar to Vec::retain_mut to remove or modify the attributes of an element while iterating over them.

This is currently doable, but involves iterating over the attributes, collecting and cloning their names, potentially cloning the new value, and searching the attribute in the attribute list every time we want to remove or modify an attribute.

The proposed function would make this much more efficient and simpler to implement.
I guess this function would have to be available on StartTag and on Element. I am not quite sure about the naming, but I'd be willing to contribute this.

@Fxxxlei
Copy link
Author

Fxxxlei commented Feb 8, 2023

Since we have to reset StartTag::raw if any attribute is modified, we cannot just pass a mutable reference to an Attribute.

We could either pass a wrapper to an Attribute, or return an enum in our callback (Noop, Remove, Replace(new_value))

Each solution has some drawback. The solution with the wrapper is more complex, while the solution with the return value requires the new value to be owned. I personally prefer the second solution.

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

No branches or pull requests

1 participant