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 Clone for DeEvent, PayloadEvent and Text #748

Merged
merged 1 commit into from
May 26, 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
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