2024-06-16 08:14:13 +00:00
|
|
|
[package]
|
|
|
|
name = "xso"
|
2024-07-26 16:24:43 +00:00
|
|
|
version = "0.1.2"
|
2024-06-16 08:14:13 +00:00
|
|
|
edition = "2021"
|
|
|
|
description = "XML Streamed Objects: similar to serde, but XML-native."
|
|
|
|
homepage = "https://xmpp.rs"
|
|
|
|
repository = "https://gitlab.com/xmpp-rs/xmpp-rs"
|
|
|
|
keywords = ["xmpp", "xml", "serialization"]
|
|
|
|
categories = ["encoding"]
|
|
|
|
license = "MPL-2.0"
|
|
|
|
|
|
|
|
[dependencies]
|
2024-08-09 12:48:40 +00:00
|
|
|
rxml = { version = "0.12.0", default-features = false }
|
2024-08-12 08:16:15 +00:00
|
|
|
minidom = { version = "0.16", path = "../minidom" }
|
|
|
|
xso_proc = { version = "0.1", path = "../xso-proc", optional = true }
|
2024-06-21 15:53:37 +00:00
|
|
|
|
2024-06-26 16:36:48 +00:00
|
|
|
# optional dependencies to provide text conversion to/from types from/using
|
|
|
|
# these crates
|
xso: add traits for XML text <-> value conversion
The traits have undergone a couple iterations and this is what we end up
with. The core issue which makes this entire thing ugly is the
Orphan Rule, preventing some trait implementations relating to types
which haven't been defined in this crate.
In an ideal world, we would implement FromXmlText and IntoXmlText for
all types implementing FromStr and/or fmt::Display.
This comes with two severe issues:
1. Downstream crates cannot chose to have different
parsing/serialisation behaviour for "normal" text vs. xml.
2. We ourselves cannot define a behaviour for `Option<T>`. `Option<T>`
does not implement `FromStr` (nor `Display`), but the standard
library *could* do that at some point, and thus Rust doesn't let us
implement e.g. `FromXmlText for Option<T> where T: FromXmlText`,
if we also implement it on `T: FromStr`.
The second one hurts particularly once we get to optional attributes:
For these, we need to "detect" that the type is in fact `Option<T>`,
because we then need to invoke `FromXmlText` on `T` instead of
`Option<T>`. Unfortunately, we cannot do that: macros operate on token
streams and we have no type information available.
We can of course match on the name `Option`, but that breaks down when
users re-import `Option` under a different name. Even just enumerating
all the possible correct ways of using `Option` from the standard
library (there are more than three) would be a nuisance at best.
Hence, we need *another* trait or at least a specialized implementation
of `FromXmlText for Option<T>`, and we cannot do that if we blanket-impl
`FromXmlText` on `T: FromStr`.
That makes the traits what they are, and introduces the requirement that
we know about any upstream crate which anyone might want to parse from
or to XML. This sucks a lot, but that's the state of the world. We are
late to the party, and we cannot expect everyone to do the same they
have done for `serde` (many crates have a `feature = "serde"` which then
provides Serialize/Deserialize trait impls for their types).
2024-06-25 15:36:36 +00:00
|
|
|
# NOTE: because we don't have public/private dependencies yet and cargo
|
|
|
|
# defaults to picking the highest matching version by default, the only
|
|
|
|
# sensible thing we can do here is to depend on the least version of the most
|
|
|
|
# recent semver of each crate.
|
2024-08-12 08:16:15 +00:00
|
|
|
jid = { version = "0.11", path = "../jid", optional = true }
|
2024-07-25 08:34:39 +00:00
|
|
|
uuid = { version = "1", optional = true }
|
|
|
|
base64 = { version = "0.22", optional = true }
|
xso: add traits for XML text <-> value conversion
The traits have undergone a couple iterations and this is what we end up
with. The core issue which makes this entire thing ugly is the
Orphan Rule, preventing some trait implementations relating to types
which haven't been defined in this crate.
In an ideal world, we would implement FromXmlText and IntoXmlText for
all types implementing FromStr and/or fmt::Display.
This comes with two severe issues:
1. Downstream crates cannot chose to have different
parsing/serialisation behaviour for "normal" text vs. xml.
2. We ourselves cannot define a behaviour for `Option<T>`. `Option<T>`
does not implement `FromStr` (nor `Display`), but the standard
library *could* do that at some point, and thus Rust doesn't let us
implement e.g. `FromXmlText for Option<T> where T: FromXmlText`,
if we also implement it on `T: FromStr`.
The second one hurts particularly once we get to optional attributes:
For these, we need to "detect" that the type is in fact `Option<T>`,
because we then need to invoke `FromXmlText` on `T` instead of
`Option<T>`. Unfortunately, we cannot do that: macros operate on token
streams and we have no type information available.
We can of course match on the name `Option`, but that breaks down when
users re-import `Option` under a different name. Even just enumerating
all the possible correct ways of using `Option` from the standard
library (there are more than three) would be a nuisance at best.
Hence, we need *another* trait or at least a specialized implementation
of `FromXmlText for Option<T>`, and we cannot do that if we blanket-impl
`FromXmlText` on `T: FromStr`.
That makes the traits what they are, and introduces the requirement that
we know about any upstream crate which anyone might want to parse from
or to XML. This sucks a lot, but that's the state of the world. We are
late to the party, and we cannot expect everyone to do the same they
have done for `serde` (many crates have a `feature = "serde"` which then
provides Serialize/Deserialize trait impls for their types).
2024-06-25 15:36:36 +00:00
|
|
|
|
2024-06-21 15:53:37 +00:00
|
|
|
[features]
|
2024-08-09 12:49:27 +00:00
|
|
|
macros = [ "dep:xso_proc", "rxml/macros" ]
|
2024-06-21 15:53:37 +00:00
|
|
|
minidom = [ "xso_proc/minidom"]
|
|
|
|
panicking-into-impl = ["xso_proc/panicking-into-impl"]
|
2024-07-26 15:07:05 +00:00
|
|
|
|
|
|
|
[package.metadata.docs.rs]
|
|
|
|
all-features = true
|
|
|
|
rustdoc-args = ["--cfg", "docsrs"]
|