stellar / rs-stellar-xdr

Rust lib for Stellar XDR.
Apache License 2.0
20 stars 27 forks source link

Option<T> <> ScVal requires infallible conversions but shouldn't #345

Open leighmcculloch opened 8 months ago

leighmcculloch commented 8 months ago

It appears that the Option type only has conversions to ScVal as infallible, and therefore only has conversions for versions of T that are also infallible:

https://github.com/stellar/rs-stellar-xdr/blob/8b9d623ef40423a8462442b86997155f2c04d3a1/src/curr/scval_conversions.rs#L507-L529

This makes the use and compatibility of Option as a Soroban type limited, since many other types are only convertible through the Try interface because they can error.

Custom types only require TryFrom and not From.

Option should be implemented for TryFrom, instead of From, so that it is usable in custom types with a wider variety of T's.

Related discussion:

leighmcculloch commented 8 months ago

Introducing TryFrom conversions for Option may have some conflicts on other trait impls, so we'll need to test the change that attempts to fix this up most of the stack up to at least the SDK before committing to a fix.