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

Improve API for creating new elements #3

Closed
matt2xu opened this issue Feb 26, 2016 · 3 comments
Closed

Improve API for creating new elements #3

matt2xu opened this issue Feb 26, 2016 · 3 comments

Comments

@matt2xu
Copy link

matt2xu commented Feb 26, 2016

Instead of Element::new(name, attributes), we could do separate the text and attributes part:

  1. Element::new(text) // works for any kind of element: text, comment, start, end...
  2. element.add_attributes(iter) // only useful for start elements

This way, no need to pass an empty iterator for elements where attributes don't make sense (text or comment).

I would also change the Element::new to use an AsRef<[u8]> for the name, to allow faster/easier creation of elements from existing ones.

@tafia
Copy link
Owner

tafia commented Feb 26, 2016

Looks like a good idea.

For the attributes, I'd prefer extend_attributes(iter) to consume an iterator (a-la Vec).
A push_attribute could be useful too (could be internally used by the extend version) because one does not always have an iterator at hand.

@matt2xu
Copy link
Author

matt2xu commented Feb 26, 2016

👍 I'll look into it.

@tafia
Copy link
Owner

tafia commented Feb 29, 2016

closed by #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants