[serde-ser] Remove validation of expected length
Problem solved by the enhancement
Multiple Serde Serializer methods take a len argument, for example Serializer::serialize_seq. Serde JSON does not seem to actually validate this argument, it just checks it to special-case empty containers, see e.g. serialize_seq for writing to Write or serialize_seq for creating a Value.
Struson currently validates the length and returns a SerializerError::IncorrectElementsCount on mismatch. The intention was to help users detect incorrect handwritten Serialize implementations. However, this validation causes the following issues:
- It might be too strict, maybe the length is only an estimation or upper bound in some cases (?)
- The logic in Struson might be faulty, preventing serialization of Serde derived
Serialize(e.g. #41)
Enhancement description
Remove the validation of the expected length, and remove SerializerError::IncorrectElementsCount
Alternatives / workarounds
Fix the bugs in the current length checks, and verify that it behaves correctly for derived Serialize
Have implemented this experimentally in the serde-ser-remove-length-validation branch, however for now I will not merge this since the validation helps with detecting bad Serialize implementations (assuming the validation is correct).
In case the validation turns out to be incorrect or too strict, I might consider merging this in the future.