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

Fix #473: add explicit serde feature that is independent from dependency #524

Merged
merged 1 commit into from Dec 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions Cargo.toml
Expand Up @@ -164,8 +164,21 @@ escape-html = []
## [`Deserializer`]: crate::de::Deserializer
overlapped-lists = []

## Enables support for [`serde`] serialization and deserialization
serialize = ["serde"]
## Enables serialization of some types using [`serde`]. Probably your rarely will
## need this feature enabled.
##
## This feature does NOT provide XML serializer or deserializer. You should use
## the `serialize` feature for that instead.
# Cannot name "serde" to avoid clash with dependency.
# "dep:" prefix only avalible from Rust 1.60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that with edition 2021 / MSRV 1.60, it is possible to simplify all of this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in Rust 1.60 it is possible to write

[dependencies]
serde = { version = "1.0", optional = true }

[features]
# depend on the dependency "serde" instead of feature "serde"
# (which will enable "derive" feature of "serde" which is not required
# for the "serialize" feature)
serialize = ["dep:serde"] 

# depend on "serde" dependency with enabled feature "derive"
serde = ["serde/derive"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want to bump the MSRV right now then we should file an issue to simplify this in the future. I wouldn't be against bumping MSRV though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create an issue if you wish. Anyway, I marked this place with Rust version that is required for more modern solution, so it can be grepped.

I think, this that having more modern solution is not critical, so it is better to avoid bumping MSRV just for it. Otherwise, probably some of our dependents will not happy with that.

serde-types = ["serde/derive"]

## Enables support for [`serde`] serialization and deserialization. When this
## feature is enabled, quick-xml provides serializer and deserializer for XML.
##
## This feature does NOT enables serializaton of the types inside quick-xml.
## If you need that, use the `serde-types` feature.
serialize = ["serde"] # "dep:" prefix only avalible from Rust 1.60

[package.metadata.docs.rs]
# document all features
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -40,6 +40,8 @@
```
- [#523]: Fix incorrect handling of `xs:list`s with encoded spaces: they still
act as delimiters, which is confirmed also by mature XmlBeans Java library
- [#473]: Fix a hidden requirement to enable serde's `derive` feature to get
quick-xml's `serialize` feature for `edition = 2021` or `resolver = 2` crates

### Misc Changes

Expand All @@ -65,7 +67,9 @@

Refer to [documentation] for details.
- [#521]: MSRV bumped to 1.52.
- [#473]: `serde` feature that used to make some types serializable, renamed to `serde-types`

[#473]: https://github.com/tafia/quick-xml/issues/473
[#490]: https://github.com/tafia/quick-xml/pull/490
[#500]: https://github.com/tafia/quick-xml/issues/500
[#514]: https://github.com/tafia/quick-xml/issues/514
Expand Down
8 changes: 4 additions & 4 deletions src/name.rs
Expand Up @@ -16,7 +16,7 @@ use std::fmt::{self, Debug, Formatter};
///
/// [qualified name]: https://www.w3.org/TR/xml-names11/#dt-qualname
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde-types", derive(serde::Deserialize, serde::Serialize))]
pub struct QName<'a>(pub &'a [u8]);
impl<'a> QName<'a> {
/// Converts this name to an internal slice representation.
Expand Down Expand Up @@ -133,7 +133,7 @@ impl<'a> AsRef<[u8]> for QName<'a> {
///
/// [local (unqualified) name]: https://www.w3.org/TR/xml-names11/#dt-localname
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde-types", derive(serde::Deserialize, serde::Serialize))]
pub struct LocalName<'a>(&'a [u8]);
impl<'a> LocalName<'a> {
/// Converts this name to an internal slice representation.
Expand Down Expand Up @@ -183,7 +183,7 @@ impl<'a> From<QName<'a>> for LocalName<'a> {
///
/// [namespace prefix]: https://www.w3.org/TR/xml-names11/#dt-prefix
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde-types", derive(serde::Deserialize, serde::Serialize))]
pub struct Prefix<'a>(&'a [u8]);
impl<'a> Prefix<'a> {
/// Extracts internal slice
Expand Down Expand Up @@ -225,7 +225,7 @@ pub enum PrefixDeclaration<'a> {
///
/// [namespace name]: https://www.w3.org/TR/xml-names11/#dt-NSName
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde-types", derive(serde::Deserialize, serde::Serialize))]
pub struct Namespace<'a>(pub &'a [u8]);
impl<'a> Namespace<'a> {
/// Converts this namespace to an internal slice representation.
Expand Down