Add infallible From conversions for types to ScVal #1338
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Add infallible From conversions for types to ScVal, replacing the existing fallible TryFrom conversions.
Why
When I look through tests I see lots of
try_into().unwrap()
when converting types to their ScVal values. This is unnecessary, we know that the conversions will succeed because the host won't give the SDK types that aren't valid and couldn't be converted. It's just a result of the way the Rust types are setup we can't guarantee the type is always convertible, but in practice they are.Note that this is not really a breaking change, because in the Rust core lib there is a blanket impl for all From conversions to also provide a TryFrom conversion. The only behaviour change is that if there were cases that would fail conversion previously a panic will occur instead of an error when using a TryFrom to do the conversion. In all cases there is no expected failure because the Env guarantees valid host types to be created and we're converting host types to ScVal types.