Skip to content

Commit

Permalink
Implement From<QName> for BytesStart and BytesEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun authored and dralley committed Jun 16, 2024
1 parent 65bf651 commit d66df32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit d66df32

Please sign in to comment.