-
Notifications
You must be signed in to change notification settings - Fork 349
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
Add SupplyResponse::new #1552
Add SupplyResponse::new #1552
Conversation
Hmm, this is a problem. We have this in a different place as well. The moment this constructor is added, we cannot add fields to the response type anymore. And this is the reason there is Where do you need contructing a |
Yes exactly, just for testing. You can take a look at these PRs if you're interested |
If backward compatibility is the concern, how about this solution. Suppose I have this struct: #[non_exhaustive]
struct MyStruct {
a: String,
b: String,
c: String,
}
impl MyStruct {
pub fn new(a: String, b: String, c: String) -> Self {
Self { a, b, c }
}
} Let's say in cosmwasm v1.2 we want to add a new field #[non_exhaustive]
struct MyStruct {
a: String,
b: String,
c: String,
#[cfg(feature = "cosmwasm_1_2")]
d: String,
}
impl MyStruct {
#[cfg(not(feature = "cosmwasm_1_2"))]
pub fn new(a: String, b: String, c: String) -> Self {
Self { a, b, c }
}
#[cfg(feature = "cosmwasm_1_2")]
pub fn new(a: String, b: String, c: String, d: String) -> Self {
Self { a, b, c, d }
}
} This way, anyone who doesn't enable the |
Unfortunately this conflicts with the idea that Rust features must be additive. In the given example, a We have such problems in the codebase around the ibc3 feature but they will be removed as soon as we get the chance. |
What if instead we implement fn construct_me(testing_amount: Coin) -> SupplyResponse {
let mut res = SupplyResponse::default();
res.amount = testing_amount;
res
} |
Sounds like a good solution |
Could you check out the work in #1560 for an implementation of that approach? |
Pretty much self explanatory, without this, consumers of cosmwasm-std can't construct new SupplyResponse structs