Skip to content

Commit

Permalink
Switch to new serializer
Browse files Browse the repository at this point in the history
Fixes tafia#252
Fixes tafia#280
Fixes tafia#287
Fixes tafia#343
Fixes tafia#346
Fixes tafia#361
Partially addresses tafia#368
Fixes tafia#429
Fixes tafia#430

Fixes all tests

Co-authored-by: Daniel Alley <dalley@redhat.com>
  • Loading branch information
2 people authored and Joseph Gilby committed Nov 5, 2022
1 parent 5d4e031 commit fce286e
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 572 deletions.
14 changes: 14 additions & 0 deletions Changelog.md
Expand Up @@ -14,11 +14,24 @@

### Bug Fixes

- [#490]: Ensure that serialization of map keys always produces valid XML names.
In particular, that means that maps with numeric and numeric-like keys (for
example, `"42"`) no longer can be serialized because [XML name] cannot start
from a digit

### Misc Changes

- [#490]: Removed `$unflatten=` special prefix for fields for serde (de)serializer, because:
- it is useless for deserializer
- serializer was rewritten and does not require it anymore

This prefix allowed you to serialize struct field as an XML element and now
replaced by a more thoughtful system explicitly indicating that a field should
be serialized as an attribute by prepending `@` character to its name
- [#490]: Removed `$primitive=` prefix. That prefix allowed you to serialize struct
field as an attribute instead of an element and now replaced by a more thoughtful
system explicitly indicating that a field should be serialized as an attribute
by prepending `@` character to its name
- [#490]: In addition to the `$value` special name for a field a new `$text`
special name was added:
- `$text` is used if you want to map field to text content only. No markup is
Expand All @@ -31,6 +44,7 @@
Refer to [documentation] for details.

[#490]: https://github.com/tafia/quick-xml/pull/490
[XML name]: https://www.w3.org/TR/xml11/#NT-Name
[documentation]: https://docs.rs/quick-xml/0.27.0/quick_xml/de/index.html#difference-between-text-and-value-special-names

## 0.26.0 -- 2022-10-23
Expand Down
17 changes: 0 additions & 17 deletions README.md
Expand Up @@ -132,23 +132,6 @@ struct Foo {

Read about the difference in the [documentation](https://docs.rs/quick-xml/latest/quick_xml/de/index.html#difference-between-text-and-value-special-names).

### Serializing unit variants as primitives

The `$primitive` prefix lets you serialize enum variants without associated values (internally referred to as _unit variants_) as primitive strings rather than self-closing tags. Consider the following definitions:

```rust,ignore
enum Foo {
#[serde(rename = "$primitive=Bar")]
Bar
}
struct Root {
foo: Foo
}
```

Serializing `Root { foo: Foo::Bar }` will then yield `<Root foo="Bar"/>` instead of `<Root><Bar/></Root>`.

### Performance

Note that despite not focusing on performance (there are several unnecessary copies), it remains about 10x faster than serde-xml-rs.
Expand Down
1 change: 0 additions & 1 deletion src/de/mod.rs
Expand Up @@ -356,7 +356,6 @@ use std::num::NonZeroUsize;
pub(crate) const TEXT_KEY: &str = "$text";
/// Data represented by any XML markup inside
pub(crate) const VALUE_KEY: &str = "$value";
pub(crate) const PRIMITIVE_PREFIX: &str = "$primitive=";

/// Simplified event which contains only these variants that used by deserializer
#[derive(Debug, PartialEq, Eq)]
Expand Down

0 comments on commit fce286e

Please sign in to comment.