-
Notifications
You must be signed in to change notification settings - Fork 328
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
Make our Uint types homogenous and create a macro for them (keep it DRY!) #1114
Comments
Note: the macro is only for code generation inside of cosmwasm_std. The usage of the types should not need to use a macro. |
I was wondering if we should have two macros:
This has two advantages
|
We could try doing something like that and seeing how well it works, sure. |
For primitives you could simply provide serializers and have users use them in their schemas, that's how we've dealt with i128: pub mod int128 {
use serde::{self, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(bigint: &i128, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&bigint.to_string())
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<i128, D::Error>
where
D: Deserializer<'de>,
{
let str = String::deserialize(deserializer)?;
str::parse::<i128>(&str).map_err(serde::de::Error::custom)
}
} It becomes slightly more code in serializable structs: #[serde(with = "int128")]
#[schemars(with = "i128")]
pub value: i128, but we get to use the native types without wrapper methods. |
Nice trick, @archseer. I wasn't aware it's that easy to build custom serializers. We'll still keep our types, but good to know. |
We added u128 and i128 support to Can we consider this closed now? |
I'm not convinced that we need macros to avoid the duplication. Especially since |
Homogenous meaning it'd be cool if they all used the same thing internally (e.g. Parity's uint types).
A macro (or maybe some sort of generic implementation using const generics?) would help us write all the methods, operator implementations, etc. once only rather than copy-pasting code.
The text was updated successfully, but these errors were encountered: