mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
1f679c3af7
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).
28 lines
1,005 B
TOML
28 lines
1,005 B
TOML
[package]
|
|
name = "xso"
|
|
version = "0.0.2"
|
|
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]
|
|
rxml = { version = "0.11.0", default-features = false }
|
|
minidom = { version = "^0.15" }
|
|
xso_proc = { version = "0.0.2", optional = true }
|
|
|
|
# optional dependencies to provide text conversion to/from types from these crates
|
|
# 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.
|
|
jid = { version = "^0.10", optional = true }
|
|
uuid = { version = "^1", optional = true }
|
|
|
|
[features]
|
|
macros = [ "dep:xso_proc" ]
|
|
minidom = [ "xso_proc/minidom"]
|
|
panicking-into-impl = ["xso_proc/panicking-into-impl"]
|