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 From<QName> for BytesStart and BytesEnd #758

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### New Features

- [#758]: Implemented `From<QName>` for `BytesStart` and `BytesEnd`.

### Bug Fixes

- [#755]: Fix incorrect missing of trimming all-space text events when
Expand All @@ -23,6 +25,7 @@

[#650]: https://github.com/tafia/quick-xml/issues/650
[#755]: https://github.com/tafia/quick-xml/pull/755
[#758]: https://github.com/tafia/quick-xml/pull/758


## 0.32.0 -- 2024-06-10
Expand Down
18 changes: 17 additions & 1 deletion src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ impl<'a> BytesStart<'a> {
}

/// Creates new paired close tag
#[inline]
pub fn to_end(&self) -> BytesEnd {
BytesEnd::wrap(self.name().into_inner().into())
BytesEnd::from(self.name())
}

/// Gets the undecoded raw tag name, as present in the input stream.
Expand Down Expand Up @@ -322,6 +323,14 @@ impl<'a> Deref for BytesStart<'a> {
}
}

impl<'a> From<QName<'a>> for BytesStart<'a> {
#[inline]
fn from(name: QName<'a>) -> Self {
let name = name.into_inner();
Self::wrap(name, name.len())
}
}

#[cfg(feature = "arbitrary")]
impl<'a> arbitrary::Arbitrary<'a> for BytesStart<'a> {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Expand Down Expand Up @@ -673,6 +682,13 @@ impl<'a> Deref for BytesEnd<'a> {
}
}

impl<'a> From<QName<'a>> for BytesEnd<'a> {
#[inline]
fn from(name: QName<'a>) -> Self {
Self::wrap(name.into_inner().into())
}
}

#[cfg(feature = "arbitrary")]
impl<'a> arbitrary::Arbitrary<'a> for BytesEnd<'a> {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Expand Down