Mingun
4f922e4e5b
Implement serialization of flattened tuple variants of externally tagged enums
...
The Container struct
struct Container {
#[serde(flatten)]
enum_field: Enum,
}
enum Enum {
Tuple(u32, u32),
}
now can be serialized to JSON as
{ "enum_field": [1, 2] }
Deserialization already works
Fixes (1):
flatten::enum_::externally_tagged::tuple
2023-07-11 22:00:10 +05:00
Mingun
993966600e
Implement tests for crate::private::de::content::VariantDeserializer
...
failures (1):
flatten::enum_::externally_tagged::tuple
2023-07-11 21:59:22 +05:00
Mingun
5b96cf1bde
Use traditional order for enum variants (Unit, Newtype, Tuple, Struct) and names for tag and content fields
2023-07-11 21:58:43 +05:00
Mingun
f3d50e5209
Use FromIterator to fill HashMap
2023-07-11 21:58:14 +05:00
Mingun
ab21d4d017
Merge assert_de_tokens and assert_ser_tokens into assert_tokens
2023-07-11 21:57:49 +05:00
Mingun
f7c5d93e6a
Pull up types from function into module, unify style
2023-07-11 21:57:22 +05:00
Mingun
52a7d40e6e
Rename test types so their names reflects, what's tested
2023-07-11 21:56:53 +05:00
Mingun
348bc6b257
Move flatten enum tests to a dedicated module
...
(review with "ignore whitespace" option on and editor that shows line moves,
for example, TortoiseGitMerge)
2023-07-11 21:56:22 +05:00
Mingun
4cf1fec575
Replace several linked variables with enumeration for tuples
2023-06-26 20:55:52 +05:00
Mingun
ee7d77defa
Replace several linked variables with enumeration for structs
2023-06-26 20:55:52 +05:00
Mingun
d0dfc4577e
Replace enum with boolean parameter
2023-06-26 20:55:52 +05:00
Mingun
bbbd1d24c9
Move deserialize_generated_identifier out from if because the call is same in both arms
2023-06-26 20:55:51 +05:00
Mingun
fb3a9e0d7c
Simplify check for missing fields
2023-06-26 20:55:51 +05:00
Mingun and Oliver Schneider
5ffebeb6ef
Actually, field_names_idents can be calculated using the same code in both cases
...
When !cattrs.has_flatten() all fields is !field.attrs.flatten()
Co-authored-by: Oliver Schneider <oli-obk@users.noreply.github.com >
2023-06-26 20:55:51 +05:00
Mingun
75db73066b
Inline deserialize_struct_as_map_visitor and deserialize_struct_as_struct_visitor
2023-06-26 20:55:51 +05:00
Mingun
2796833c82
Pull up call to deserialize_map because it's identical
2023-06-26 20:55:50 +05:00
Mingun
95730dc7f7
Reorder variables to match order in final quote!
2023-06-26 20:55:50 +05:00
Mingun
795261919f
Generate visit_seq only when needed
2023-06-26 20:55:50 +05:00
Mingun
3783a30ae7
Remove TaggedContent, replace it by a tuple
...
That type does not give any benefits so we can avoid that hidden public but no-API struct
2023-06-24 20:49:49 +05:00
Mingun
b61ec84886
Remove implementation of DeserializeSeed for TaggedContentVisitor
...
It is not used anywhere
2023-06-24 20:48:09 +05:00
Mingun
780a461d92
Generate one deserializer rather than in each arm
2023-06-24 20:48:08 +05:00
Mingun
2c1f62d4b4
Fix incorrect count of fields passed to tuple deserialization methods
...
This count should mean the number of fields expected in the serialized form,
so if some fields are skipped, they shouldn't be counted
Methods affected:
- Deserializer::deserialize_tuple
- Deserializer::deserialize_tuple_struct
- VariantAccess::tuple_variant
2023-05-28 23:17:05 +05:00
Mingun
ab6588ef74
Extract duplicated code into a function
2023-05-08 10:39:30 +05:00
Mingun
1d11f03449
Extract logic of taking flattened fields into a function
2023-05-08 10:39:27 +05:00
Mingun
e11d01fe1d
Remove constructors for FlatMapAccess and FlatStructAccess
...
They are used only in one place each, so for simplifying understanding it is better to inline them
2023-05-08 09:40:06 +05:00
Mingun
a901f50850
FlatMapAccess and FlatStructAccess does not need to be public
2023-05-08 09:37:15 +05:00
Mingun
c399e9c368
Remove FlatInternallyTaggedAccess because it is the same as FlatMapAccess
2023-05-08 09:25:18 +05:00
Mingun
51799dd654
Allow to flatten IgnoredAny to ignore any additional data
...
Although any additional fields in struct by default are ignored, sometimes
this can be useful, if you use generic structures, for example
2023-04-30 01:59:55 +05:00
Mingun
732ac49321
Implement PartialEq for IgnoredAny so it can be used in tests
2023-04-30 01:58:07 +05:00
Mingun
ac8ea72d88
Don't panic in serde_test
...
Panics lead to reporting errors in tests inside of serde_test internals,
returning errors moves the report location to the corresponding assert_tokens
expression
2023-04-30 00:06:51 +05:00
Mingun
2d88228b7d
Remove unused after a649190a4d .gitattributes
2023-04-26 23:54:09 +05:00
Mingun
38c130a303
Do not generate DeserializeSeed impl when not needed
...
This function is called for untagged, internally and externally tagged enums,
but `deserializer` parameter is `None` only for the latest. Only when it's `None`
`DeserializeSeed` impl is used
2023-02-27 21:08:30 +05:00
Mingun
c7393614ff
Fix generation of non-existent lifetime 'de when enum contains a #[serde(flatten)] field and a 'static reference
2023-02-27 21:03:34 +05:00
Mingun
e0fc46783d
Add test with generic deserialize_with function
2021-06-12 18:47:08 +05:00
Mingun
ca772a14f9
Get rid of useless DeserializeWith wrapper
2021-06-12 18:38:03 +05:00
Mingun
b60c03ec3f
Extend test_internally_tagged_newtype_variant_containing_unit_struct to cover structs and seqs
2021-02-02 09:00:04 +05:00
Mingun
3257851192
Extend test_internally_tagged_struct_variant_containing_unit_variant to cover maps and seqs
2021-02-02 08:59:59 +05:00
Mingun
5cbc8439ea
Show correct location in error messages by tracking caller of utility assert_tokens functions
2020-10-28 09:11:54 +05:00
Mingun
97c350a95e
Forward Readable|Compact next_entry_seed to underlying next_entry_seed instead of usage of default implementation
...
Difference is noticeable for deserializers that rely on call of next_entry_seed
(for example, current quick-xml supports only next_entry_seed)
2020-10-28 01:05:27 +05:00
Mingun
920a77ad61
Fix incorrect messages in serialized tokens assertions
...
Serializer contains expected tokens, called methods provide actual tokens
2020-10-28 01:05:27 +05:00
Mingun
7a7a182ab6
Allow borrow for field identifiers
2020-10-23 19:03:18 +05:00
Mingun
9e1f573f88
Use forward_deserializer macro for define StrDeserializer for IdentifierDeserializer
2020-10-23 19:03:18 +05:00
Mingun
094f63b86a
Introduce a forward_deserializer macro.
...
It helps to create deserializers that can stop time: save the value and then use visitor to get it later!
2020-10-23 19:03:14 +05:00
Mingun
42fa79455e
Make BytesDeserializer public
2020-10-23 12:13:57 +05:00
Mingun
104ad9a7dd
Allow to define custom expectation message for type with #[serde(expecting = "...")]
...
Closes #1883
2020-10-23 01:23:01 +05:00
Mingun
23c14e5f33
Allow to run assert_de_tokens_error on token sequence that is not expected by enum deserializer
...
Before that fix following code panics, because `Token::Unit` was unexpected by test deserializer:
```
#[derive(Deserialize)]
enum E { ... }
assert_de_tokens_error::<E>(&[Token::Unit], "...");
```
2020-10-22 23:50:48 +05:00
Mingun
e80571751d
Allow borrowed and owned strings and bytes and u8, u16, u64 for variant keys in serde_test
2020-10-22 20:43:14 +05:00
Mingun
0737474640
Allow field identifiers be any numbers if #[serde(other)] is used
...
Thus behavior synchronized between string/bytes identifiers and numeric identifiers
2020-10-22 16:35:28 +05:00
Mingun
34de1e00c8
Implement IdentifierDeserializer for u64 instead of u32 because all identifiers deserialized with visit_u64
2020-10-22 16:35:28 +05:00
Mingun
f6eb34a830
Assert that numeric field identifiers correctly deserialized (now failing)
2020-10-22 16:35:28 +05:00
Mingun
e6d2322e68
Fix misprint in the error message
2020-10-12 00:03:21 +05:00
Mingun
db3074a40f
Implement IntoDeserializer for Cow<[u8]>
2020-10-04 13:38:31 +05:00
Mingun
2e821eab4b
Make impl IntoDeserializer for &[u8] public
2020-10-03 16:43:31 +05:00