Skip to content

Commit

Permalink
Merge pull request #748 from Mingun/cloneable-de-event
Browse files Browse the repository at this point in the history
Implement `Clone` for `DeEvent`, `PayloadEvent` and `Text`
  • Loading branch information
Mingun authored May 26, 2024
2 parents 5fd130a + 835261f commit 42e3e48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ to get an offset of the error position. For `SyntaxError`s the range
To get an error position use `error_position()`.
- [#738]: Add an example of how to deserialize XML elements into Rust enums using an
intermediate custom deserializer.
- [#748]: Implement `Clone` for [`DeEvent`], [`PayloadEvent`] and [`Text`].

[#275]: https://github.com/tafia/quick-xml/issues/275
[#362]: https://github.com/tafia/quick-xml/issues/362
Expand All @@ -82,6 +83,10 @@ to get an offset of the error position. For `SyntaxError`s the range
[#705]: https://github.com/tafia/quick-xml/pull/705
[#722]: https://github.com/tafia/quick-xml/pull/722
[#738]: https://github.com/tafia/quick-xml/pull/738
[#748]: https://github.com/tafia/quick-xml/pull/748
[`DeEvent`]: https://docs.rs/quick-xml/latest/quick_xml/de/enum.DeEvent.html
[`PayloadEvent`]: https://docs.rs/quick-xml/latest/quick_xml/de/enum.PayloadEvent.html
[`Text`]: https://docs.rs/quick-xml/latest/quick_xml/de/struct.Text.html


## 0.31.0 -- 2023-10-22
Expand Down
9 changes: 6 additions & 3 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,11 +2026,14 @@ pub(crate) const VALUE_KEY: &str = "$value";
/// events. _Consequent_ means that events should follow each other or be
/// delimited only by (any count of) [`Comment`] or [`PI`] events.
///
/// Internally text is stored in `Cow<str>`. Cloning of text is cheap while it
/// is borrowed and makes copies of data when it is owned.
///
/// [`Text`]: Event::Text
/// [`CData`]: Event::CData
/// [`Comment`]: Event::Comment
/// [`PI`]: Event::PI
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Text<'a> {
text: Cow<'a, str>,
}
Expand All @@ -2056,7 +2059,7 @@ impl<'a> From<&'a str> for Text<'a> {
////////////////////////////////////////////////////////////////////////////////////////////////////

/// Simplified event which contains only these variants that used by deserializer
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DeEvent<'a> {
/// Start tag (with attributes) `<tag attr="value">`.
Start(BytesStart<'a>),
Expand Down Expand Up @@ -2088,7 +2091,7 @@ pub enum DeEvent<'a> {
///
/// [`Text`]: Event::Text
/// [`CData`]: Event::CData
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum PayloadEvent<'a> {
/// Start tag (with attributes) `<tag attr="value">`.
Start(BytesStart<'a>),
Expand Down

0 comments on commit 42e3e48

Please sign in to comment.