You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the existing issues. There is no such request yet, but here's a request with the most similar vibe: uint: add casting from/to U64 #691
Experiencing problems? Have you tried our Stack Exchange first?
This is not a support question.
Question:
What is recommended way to convert one type of uint to another?
Background:
I've developed a high-level lib for creating custom DeFi-oriented types that are implemented in pure Rust, where uint types serve as underlying types.
Details:
In certain scenarios, I need to expand the type to prevent overflow in intermediate calculations. For instance, there are cases where I must extend the type from U256 to U512. I'm exploring the best approach to convert between different uint types.
Based on my observations, it seems that try_from is only implemented for primitive types. One option is to manually rewrite the u64 values, but I believe there might be a more elegant solution. Perhaps it's worth considering the addition of a try_from implementation for converting between types at the uint library level.
As an illustration, consider the following two types:
In this case the the conversion is always infallible, so why the try?
I am not sure what exactly you need, but if its just conversion methods then sure we can use those 😄
I meant a generic conversion between any types of uints, so try can be useful if the value doesn't fit. What's more, uint dependency is required in my case.
Is there an existing issue?
Experiencing problems? Have you tried our Stack Exchange first?
Question:
What is recommended way to convert one type of uint to another?
Background:
I've developed a high-level lib for creating custom DeFi-oriented types that are implemented in pure Rust, where uint types serve as underlying types.
Details:
In certain scenarios, I need to expand the type to prevent overflow in intermediate calculations. For instance, there are cases where I must extend the type from
U256
toU512
. I'm exploring the best approach to convert between different uint types.Based on my observations, it seems that
try_from
is only implemented for primitive types. One option is to manually rewrite the u64 values, but I believe there might be a more elegant solution. Perhaps it's worth considering the addition of atry_from
implementation for converting between types at the uint library level.As an illustration, consider the following two types:
In this context, creating a
U512
type based on aU256
instance could look like this:Are you willing to help with this request?
I am willing to create a proposal for implementation if the feature is deemed useful.
The text was updated successfully, but these errors were encountered: