Document ToXdr and FromXdr traits#1767
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the Soroban SDK’s XDR conversion API documentation by expanding the rustdoc for ToXdr and FromXdr, clarifying how values are serialized/deserialized via Val/ScVal and what error/panic behavior to expect.
Changes:
- Clarified
ToXdrsemantics (conversion toValthen serialization asScValXDR) and added a short usage example. - Clarified
FromXdrsemantics (deserializeScValXDR toVal, then convert) and documented error/panic behavior with an example.
|
Approving - but it might be worth exploring having Leaving as an extra comment to get your thoughts. |
Yeah, but that's a protocol change, so not going to do that here. Take that to a GitHub Discussion to pursue. |
What
Added documentation to the
ToXdrandFromXdrtraits explaining the two-step serialization process: values are first converted to aVal, then serialized to XDR in theirScValform. AddedErrorsandPanicssections toFromXdrandfrom_xdr, doc examples on both traits, and doc comments on theto_xdr,from_xdrmethods and theErrorassociated type.Why
FromXdr::from_xdrpanics if the provided bytes are not valid XDR for anScVal, but returns an error if theValcannot be converted into the target type. This distinction was undocumented. The panic originates from the host side, making it non-obvious even when reading the implementation.Close #1766