diff --git a/Changelog.md b/Changelog.md index 080d475b..8cf9c2c2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,8 @@ ### New Features +- [#758]: Implemented `From` for `BytesStart` and `BytesEnd`. + ### Bug Fixes - [#755]: Fix incorrect missing of trimming all-space text events when @@ -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 diff --git a/src/events/mod.rs b/src/events/mod.rs index 9d5d311f..593804d1 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -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. @@ -322,6 +323,14 @@ impl<'a> Deref for BytesStart<'a> { } } +impl<'a> From> 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 { @@ -673,6 +682,13 @@ impl<'a> Deref for BytesEnd<'a> { } } +impl<'a> From> 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 {