Commit graph

64 commits

Author SHA1 Message Date
Jonas Schäfer
2c5f1f096b xso: implement support for extracting data from child elements 2024-08-03 15:17:30 +02:00
Emmanuel Gil Peyrot
7f5b6fec7f xso: Allow any T: FromXmlText + AsXmlText in EmptyAsNone
This text codec was previously implemented only for Option<String>, this
extends it to all types implementing those two traits, such as numbers
or JIDs.
2024-08-03 13:43:44 +02:00
Jonas Schäfer
93ba2797be xso-proc: implement support for collections of children 2024-08-03 12:20:04 +02:00
Jonas Schäfer
c028c3b91a xso: implement exhaustive enums
These more closely mirror how enums work currently with the macros.
Non-exhaustive enums may be useful though and kind of were the natural
thing to implement.
2024-08-03 12:19:28 +02:00
Jonas Schäfer
2fe3c0cef2 xso-proc: add fancy hack to allow codec = Foo<Bar>
We can do this because we know that `x < y` cannot create a
`TextCodec<T>` for any `T`. This is because `<` is guaranteed to return
a boolean value, and we simply don't implement `TextCodec<T>` on bool.
2024-08-03 12:14:26 +02:00
Jonas Schäfer
271c31c9d4 xso: use values instead of types for text codecs
This allows stateful or configurable codecs without having to express
all configuration in the type name itself. For example, we could have a
Base64 type with configurable Base64 engines without having to duplicate
the Base64 type itself.

(Note that the different engines in the Base64 crate are values, not
types.)
2024-08-03 12:14:26 +02:00
Jonas Schäfer
4845715add xso: implement support for enums 2024-08-01 15:28:22 +02:00
Jonas Schäfer
3089832090 xso-proc: remove stripping of trailing _ from type names
Users can now rename the generated types altogether, which means that we
do not need this anymore to avoid lints.
2024-08-01 12:53:20 +00:00
Jonas Schäfer
c90752aa51 xso: add support for overriding names of generated types
In 1265f4b, we introduced a change which may cause a conflict of type
names when deriving the traits on two different types. While a
workaround existed (use `mod`s to isolate the implementation), that is
ugly.

This commit allows overriding the choice of type names.
2024-08-01 12:53:20 +00:00
Jonas Schäfer
cd9f2033f3 xso: add support for boxed children
This allows building recursive tree structures.
2024-07-27 08:24:25 +02:00
Jonas Schäfer
01336802b4 xso-proc: add support for optional children 2024-07-27 08:24:25 +02:00
Jonas Schäfer
5bd36eccfc xso-proc: add support for child elements 2024-07-26 22:31:42 +02:00
Jonas Schäfer
1265f4bb67 xso-proc: fix warnings when struct names end on _ 2024-07-26 22:31:41 +02:00
Jonas Schäfer
76cd077490 xso: Bump version to 0.1.2
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
2024-07-26 18:24:43 +02:00
Jonas Schäfer
951d23cc21 xso: add changelog entry for release 2024-07-26 18:24:12 +02:00
Jonas Schäfer
c40023a65e xso: add feature flag marker to derive macros 2024-07-26 17:11:48 +02:00
Jonas Schäfer
f798c2b5bc xso: ensure that feature-gated things render on docs.rs
How would you learn about them otherwise? This is particularly important
for the derive macros (behind the `derive` feature flag).

Fixes #133.
2024-07-26 17:07:32 +02:00
Jonas Schäfer
fce846ae3d xso: refactor Base64 text codec
This introduces support for `Cow<'_, [u8]>` (which is not needed
currently, but still good to have) and generalizes the `Option<T>`
implementation so that it doesn't have to be copied for every other type
supported to be Base64'd (we may add support for `bytes::Bytes` at some
point, for instance).
2024-07-25 22:22:55 +02:00
Jonas Schäfer
bf46248eeb xso: implement FromXmlText/AsXmlText for char 2024-07-25 22:22:55 +02:00
Jonas Schäfer
fe61a25cfd xso: improve macro for FromXmlText/AsXmlText
Now it's not limited to a single feature gate per type (or even just
feature gates: it should now also be possible to add constraints
based on OS, for example) anymore.
2024-07-25 22:22:55 +02:00
Jonas Schäfer
204c82e6b0 xso: add more doc comments throughout 2024-07-25 22:22:55 +02:00
6b4bdc1641
xso: Bump version to 0.1.1
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-25 18:53:31 +02:00
Emmanuel Gil Peyrot
2b333ce579 xso: Add an EmptyAsError text codec
As its name implies, this codec emits an error when the parsed string is
empty.
2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
f0b51decea xso: Import the ColonSeparatedHex text codec from xmpp-parsers
This codec converts from a colon-separated case-insensitive hexadecimal
string into a Vec of bytes, and back to a lowercase colon-separated
hexadecimal string.  Each byte must be separated by exactly one colon.
2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
16204a1092 xso: Import the FixedHex text codec from xmpp-parsers
This codec converts from a fixed-size case-insensitive hexadecimal
string into an array of bytes, and back to a lowercase hexadecimal
string.
2024-07-25 18:42:18 +02:00
11d40bac94 Unify version string formats
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements

"^1.2.3" is strictly equivalent to "1.2.3"

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-25 14:41:04 +00:00
Jonas Schäfer
ab35c234c8 xso: Bump version to 0.1.0
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
2024-07-25 08:25:39 +00:00
Emmanuel Gil Peyrot
6e1f24c385 xso: Apply clippy’s suggestions 2024-07-25 07:35:19 +00:00
Jonas Schäfer
ca53892e66 xso: add README files 2024-07-24 16:27:53 +02:00
Jonas Schäfer
d6d9a7aaaf Add changelog stub files for xso crates 2024-07-24 16:27:33 +02:00
Jonas Schäfer
7bc7e7a684 xso: remove remnants of IntoXml 2024-07-24 16:05:06 +02:00
Jonas Schäfer
ccf38cdf9b Port everything over to AsXml 2024-07-24 16:05:06 +02:00
Jonas Schäfer
4910b01244 xso: add text conversion traits for AsXml 2024-07-24 16:05:06 +02:00
Jonas Schäfer
569b6e327d xso: provide adapter for AsXml implementation based on Into<Element>
Analogous to the already existing `IntoXml` implementation helpers
based on an `Into<Element>` implementation on a type, this provides
the utilities for `AsXml`.

This is of course exceptionally inefficient, but it is only needed
transitionally until we have everything migrated to derive macros or
otherwise rewritten in terms of AsXml/FromXml.
2024-07-24 16:05:06 +02:00
Jonas Schäfer
d12b6c31ea xso: implement AsXml for minidom::Element 2024-07-24 16:05:06 +02:00
Jonas Schäfer
d29b89d307 xso: introduce AsXml trait
This will soon replace the IntoXml trait. The idea here is that we
don't generally need to take ownership of values which are going to
be transformed into XML: most of the time, the XML text is created
by building a string from some more specific type, such as an
integer or an enum. Requiring to clone an entire structure for this
purpose is wasteful.

In other cases, we actually could reference data right from the structs
we are converting to XML. In those cases, assuming that an iterator
always generates owned data would be incorrect, too.

Hence, we introduce a new `Item` type which closely mirrors the
`rxml::Item` type, but where the constituents are `Cow`. In the upcoming
changes, we are going to work toward replacing all uses of `IntoXml`
with `AsXml`, as well as modifying the macros accordingly.
2024-07-24 16:05:06 +02:00
Jonas Schäfer
25adde99da Bump rxml to 0.11.1 2024-07-24 16:05:05 +02:00
0ef646db86 jid: Bump version to 0.11.1
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-23 19:02:46 +02:00
f35bbcb36d minidom: Bump version to 0.16
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-23 19:02:46 +02:00
Emmanuel Gil Peyrot
b18385cfff xso: Fix all clippy warnings 2024-07-03 16:28:11 +02:00
Jonas Schäfer
7c7f6d1f23 xso: add support for base64 text codec 2024-07-02 06:56:30 +02:00
Jonas Schäfer
c83ff286e0 xso-proc: add support for text codecs
Text codecs allow to customize the conversion of data from/to XML,
in particular in two scenarios:

1. When the type for which the behaviour is to be defined comes from a
   foreign crate, preventing the implementation of
   FromXmlText/IntoXmlText.

2. When there is not one obvious, or more than one sensible, way to
   convert a value to XML text and back.
2024-07-02 06:56:30 +02:00
Jonas Schäfer
46584f05f9 xso: refine handling of multiple #[xml(text)] fields
Previously, we only enforced the existence of at most one `#[xml(text)]`
field only at code generation time for `FromXml`. This change enforces
it at parsing time, which is more consistent and allows for a clearer
error message.
2024-07-01 08:01:42 +02:00
Jonas Schäfer
b0803f831b xso-proc: add support for parsing text content 2024-07-01 08:01:42 +02:00
Jonas Schäfer
2fb9fc6959 xso: add more doc_cfg labels 2024-06-30 13:05:37 +02:00
Jonas Schäfer
0c57be3e61 xso-proc: add support for defaulting in attribute parsing 2024-06-30 13:05:37 +02:00
Jonas Schäfer
c0fc7f49cf xso-proc: add support for non-String typed attributes 2024-06-30 13:01:36 +02:00
Jonas Schäfer
1f679c3af7 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-30 13:01:36 +02:00
Jonas Schäfer
d4d520e1f6 xso-proc: add support for built-in prefixes in attribute names
This simplifies the use of built-in XML attributes such as xml:lang.
2024-06-24 12:39:32 +02:00
Jonas Schäfer
84de7fc248 xso-proc: add support for namespaced attributes 2024-06-24 12:39:32 +02:00