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 Element API and string conversion #6

Merged
merged 1 commit into from
Feb 29, 2016
Merged

Conversation

matt2xu
Copy link

@matt2xu matt2xu commented Feb 28, 2016

Now using &[u8] everywhere in Element and Attribute, and added an AsStr trait for converting any byte slice to an &str. Renamed Element::as_bytes() to Element::name(), and added an Element::content() method. Removed Element::as_str(), no longer needed since it is handled by the AsStr trait.

On Attribute, made the value field a &[u8], to make it consistent with the type of the key; both can be converted with a call to as_str().

Will rebase if needed when #5 is merged.

@@ -44,18 +44,19 @@
//! let mut writer = XmlWriter::new(Cursor::new(Vec::new()));
//! for r in reader {
//! match r {
//! Ok(Event::Start(ref e)) if e.as_bytes() == b"this_tag" => {
//! Ok(Event::Start(ref e)) if e.name().as_str().unwrap() == "this_tag" => {
Copy link
Owner

Choose a reason for hiding this comment

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

for the example I'd prefer e.name() == b"this_tag" to show that we don't need to convert to utf8 when tags are statically known ... but this is not very important

@tafia
Copy link
Owner

tafia commented Feb 29, 2016

There is a conflict with the PR #5.
Can you please rebase?

@tafia
Copy link
Owner

tafia commented Feb 29, 2016

Could you also update the readme (just copy lib.rs example).
Thanks

@matt2xu
Copy link
Author

matt2xu commented Feb 29, 2016

@tafia rebased, and changed the example to use the raw string. I also updated the readme, but I think the easiest way to keep the readme up to date would be to not show code there, since the examples are already included in the documentation. Personally when I look at a new crate and I want to understand how to use it, I go 1) to the documentation (when it's included) 2) to the "examples" folder in the git repository. As a last resort I start browsing the source repositoy directly 😟

@tafia
Copy link
Owner

tafia commented Feb 29, 2016

I personally think the readme must show the most important features (like the one we put on each module documentation) because it is easier to read than doc (you can add context, paragraphs etc ...).
The docs must on the other hand have ALL kind examples if possible
In particular when it is just one copy paste.

Thanks for the PR!

tafia added a commit that referenced this pull request Feb 29, 2016
Improve Element API and string conversion
@tafia tafia merged commit afaf09b into tafia:master Feb 29, 2016
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