Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Implement TryFrom for ParameterValue #8420

Merged
merged 1 commit into from
Feb 1, 2023

Conversation

aborg-dev
Copy link
Contributor

This PR implements TryFrom for ParameterValue for a few types that we need while working with ParameterTable.

This helps to get rid of a lot of duplication in get_* methods, but I wasn't able to get rid of get_number that is already generic as it was violating Rust foreign trait rules (see commented out code, the exact error is [1]). Any advice there?

I also feel that TryFrom implementations have a bit more duplication than as_* methods that we had before. Particularly in re-defining the error type each time and constructing very similar error messages. Any advice here would be appreciated.

[1]

error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`ParameterValue`)
  --> core/primitives/src/runtime/parameter_table.rs:57:6
   |
57 | impl<T> TryFrom<&ParameterValue> for T
   |      ^ type parameter `T` must be covered by another type when it appears before the first local type (`ParameterValue`)

@aborg-dev aborg-dev requested a review from nagisa January 23, 2023 15:55
@aborg-dev aborg-dev marked this pull request as ready for review January 31, 2023 11:15
@aborg-dev aborg-dev requested a review from a team as a code owner January 31, 2023 11:15
This change simplifies the `ParameterTable::get` method by moving the
conversion details from `ParameterValue` to concrete types into the
`TryFrom` trait implementation.
@near-bulldozer near-bulldozer bot merged commit 6a9b7c6 into near:master Feb 1, 2023
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Feb 2, 2023
This PR implements `TryFrom` for `ParameterValue` for a few types that we need while working with `ParameterTable`.

This helps to get rid of a lot of duplication in `get_*` methods, but I wasn't able to get rid of `get_number` that is already generic as it was violating Rust foreign trait rules (see commented out code, the exact error is [1]). Any advice there?

I also feel that `TryFrom` implementations have a bit more duplication than `as_*` methods that we had before. Particularly in re-defining the error type each time and constructing very similar error messages. Any advice here would be appreciated.

[1]
```
error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`ParameterValue`)
  --> core/primitives/src/runtime/parameter_table.rs:57:6
   |
57 | impl<T> TryFrom<&ParameterValue> for T
   |      ^ type parameter `T` must be covered by another type when it appears before the first local type (`ParameterValue`)
```
@aborg-dev aborg-dev added the C-housekeeping Category: Refactoring, cleanups, code quality label Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-housekeeping Category: Refactoring, cleanups, code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants