Currently, skip_field on SerializeStruct is expected to unconditionally skip the field.
Unfortunately, this is not possible for all serialization formats, e.g. bincode, and this leads to issues like #1732, which is currently WONTFIX since serde does not wish to add further toggles.
This means that the status quo is that skip_serializing_if should only ever be used by end user crates (not libraries wishing to provide more efficient serialization, because then they can't be used with a class of deserializer). This is suboptimal and is a bit of a footgun.
Ideally, all libraries can use this feature without having to worry about it. Perhaps a path forward is to turn skip_field into skip_field_if_possible and give it the same signature as serialize_field. serde-json, etc, can continue to implement SerializeStruct without any modifications since they use the default. bincode can write skip_field_if_possible to forward to serialize_field, i.e. it can choose to never skip a field.
A downside is that the footgun still remains in a smaller form where if skip_serializing_if was used by a crate author because calling .serialize() on the field would panic (or do something bad); and with this change we're tweaking the guarantee of skip_serializing_if
I have a patch with this feature in https://github.com/serde-rs/serde/compare/master...Manishearth:skip-if-possible?expand=1
This would be a breaking change since serde-derive and serde would have to be updated in tandem, and any manual implementors (I doubt there are many) of skip_field would have to update it.
Currently,
skip_fieldonSerializeStructis expected to unconditionally skip the field.Unfortunately, this is not possible for all serialization formats, e.g. bincode, and this leads to issues like #1732, which is currently WONTFIX since serde does not wish to add further toggles.
This means that the status quo is that
skip_serializing_ifshould only ever be used by end user crates (not libraries wishing to provide more efficient serialization, because then they can't be used with a class of deserializer). This is suboptimal and is a bit of a footgun.Ideally, all libraries can use this feature without having to worry about it. Perhaps a path forward is to turn
skip_fieldintoskip_field_if_possibleand give it the same signature asserialize_field. serde-json, etc, can continue to implementSerializeStructwithout any modifications since they use the default. bincode can writeskip_field_if_possibleto forward toserialize_field, i.e. it can choose to never skip a field.A downside is that the footgun still remains in a smaller form where if
skip_serializing_ifwas used by a crate author because calling.serialize()on the field would panic (or do something bad); and with this change we're tweaking the guarantee ofskip_serializing_ifI have a patch with this feature in https://github.com/serde-rs/serde/compare/master...Manishearth:skip-if-possible?expand=1
This would be a breaking change since serde-derive and serde would have to be updated in tandem, and any manual implementors (I doubt there are many) of
skip_fieldwould have to update it.