Commit graph

54 commits

Author SHA1 Message Date
Jonas Schäfer
656125a850 xso-proc: change field def's span slightly for better UX 2024-08-05 15:33:57 +02:00
Jonas Schäfer
0361b5905b xso: implement catch-all for unknown elements 2024-08-05 15:33:57 +02:00
xmppftw
fa99c09585 Indicate which feature flag for each module/type 2024-08-05 11:14:41 +02:00
Jonas Schäfer
2358c8636e xso-proc: refactor field implementations into separate files
This decreases indentation levels on the various implemenations, it
groups the implementations together physically, and (spoiler alert!)
we'll actually need the dyn Field trait object-ness (much) later on.
2024-08-04 16:14:47 +02:00
Jonas Schäfer
19be14cdd8 xso-proc: make field into a module folder
This is in prepraration of more refactoring to come, in order to make
the individual field implementations easier to grok and look at.
2024-08-04 16:11:31 +02:00
Jonas Schäfer
b0996e3a35 xso-proc: pull out the extract code into a separate impl
This should make everything a little easier to read, because it reduces
the level of indentation involved.
2024-08-04 16:11:19 +02:00
Jonas Schäfer
c7c180feb6 xso: implement support for defaulting extracts 2024-08-04 16:07:14 +02:00
Emmanuel Gil Peyrot
1828fde78c xso-proc: Use core instead of std wherever possible 2024-08-04 12:41:17 +00:00
Emmanuel Gil Peyrot
aa518fd6c1 xso-proc: add support for extracting attributes into collections 2024-08-04 13:38:52 +02:00
Jonas Schäfer
8732ca9a28 xso: add support for extracting into collections 2024-08-03 18:19:31 +02:00
Jonas Schäfer
5590d707fb xso-proc: merge extract and normal child code 2024-08-03 18:10:11 +02:00
Jonas Schäfer
df63c2a78f xso: allow omission of namespace and name on extracts
This is a quality-of-life improvement, as it may save lots of typing in
the common case (see the diff in parsers).
2024-08-03 15:25:46 +02:00
Jonas Schäfer
2c5f1f096b xso: implement support for extracting data from child elements 2024-08-03 15:17:30 +02:00
Jonas Schäfer
5efaabc74b xso-proc: allow constructing a Compound from processed fields
This will come in handy when we implement the ability to extract
data from nested children.
2024-08-03 15:17:30 +02:00
Jonas Schäfer
e0de035448 xso-proc: deduplicate parsing of namespace / name keys 2024-08-03 15:17:30 +02:00
Jonas Schäfer
6440209f95 xso: reject duplicate children
This was an oversight. Even though we apparently don't have tests for
this anywhere, it is what the old functional macros do.
2024-08-03 11:58:19 +00: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
a20caf839f xso-proc: improve error messages for codec = .. parsing hack
Previously, if you put `codec = FixedHex<20>.filtered(..)`, it would
cause a confusing "expected `,`" message at the place of the `.`. This
code adds a helpful "try adding a `::` before the `<`" message pointing
at the `<` in the type path.
2024-08-03 12:14:26 +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
cf617e4d7e xso-proc: ensure that all meta keys are handled
See inline comments for the rationale.
2024-08-02 07:43:51 +02:00
Jonas Schäfer
4845715add xso: implement support for enums 2024-08-01 15:28:22 +02:00
Jonas Schäfer
3a56b2bb10 xso-proc: introduce trait for StructDef
Can you see it coming?
2024-08-01 15:26:38 +02:00
Jonas Schäfer
507a3df652 xso-proc: remove Span information from generated type names
By removing that, the lint won't trigger for identifiers with trailing
underscores (which become then embedded underscores which normally trips
the `non_camel_case_types` lint).
2024-08-01 12:53:20 +00: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
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
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
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
ccf38cdf9b Port everything over to AsXml 2024-07-24 16:05:06 +02:00
Emmanuel Gil Peyrot
4356cab33c xso-proc: Fix all clippy warnings 2024-07-03 16:28:11 +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
ae30221e3c xso: only fail on non-whitespace unknown text
We hereby ignore whitespace-only unexpected text, because that's
generally harmless.
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
92e69cf59f xso-proc: add debug mode for development purposes 2024-07-01 08:01:42 +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
c0d109d9be xso-proc: fix renaming attributes using a static item
This was broken by d4d520e by accident, and of course we didn't have
tests for that :-).

(we do, now)
2024-06-25 13:55:07 +00: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
Jonas Schäfer
219d682295 xso-proc: add support for renaming attributes
This is akin to `#[serde(rename = ..)]` and thus useful.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
212c5c4a83 xso-proc: add support for parsing attributes into Strings
This is bare-bones and is missing many features which we intend to add
in future commits, such as parsing from attributes whose names differ
from the field names and parsing into non-String types.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
183bef5cf6 xso-proc: completely overengineer everything for no good reason!
Well, not really, of course. All of this will make sense once we start
adding support for fields and non-struct types. Refactoring the code now
before we start to add actual member field parsing is much easier.

How do I know that this will work out? Well, my crystal ball knows it.
Don't believe me? Okay, ChatGPT told me ... Alright alright, I went
through the entire process of implementing this feature *twice* at this
point and have a pretty good idea of where to draw the abstraction lines
so that everything falls neatly into place. You'll have to trust me on
this one.

(Or, you know, check out old branches in my xmpp-rs repo. That might
work, too. `feature/derive-macro-streaming-full` might be a name to look
for if you dare.)
2024-06-23 18:43:34 +02:00
Jonas Schäfer
bf7816d321 xso-proc: refactor struct processing
If we are going to support structs with fields, it would be good to have
that struct-related code organised a little and less splashed over the
main lib.rs file.
2024-06-23 13:17:27 +02:00