Skip to content

Commit 2fbdb6a

Browse files
committed
chore: Move the macro to utils module
1 parent 4d14169 commit 2fbdb6a

File tree

8 files changed

+32
-20
lines changed

8 files changed

+32
-20
lines changed

packages/std/src/lib.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@ Builds without the std feature are currently not expected to work. If you need n
55
"#
66
);
77

8-
/// Implements a hidden constructor for query responses.
9-
// #[macro_export]
10-
macro_rules! impl_hidden_constructor {
11-
( $response:ty, $( $field: ident : $t: ty),* ) => {
12-
impl $response {
13-
/// Constructor for testing frameworks such as cw-multi-test.
14-
/// This is required because query response types should be #[non_exhaustive].
15-
/// As a contract developer you should not need this constructor since
16-
/// query responses are constructed for you via deserialization.
17-
///
18-
/// Warning: This can change in breaking ways in minor versions.
19-
#[doc(hidden)]
20-
#[allow(dead_code)]
21-
pub fn new($( $field: $t),*) -> Self {
22-
Self { $( $field ),* }
23-
}
24-
}
25-
};
26-
}
27-
288
#[macro_use]
299
extern crate alloc;
3010

@@ -61,6 +41,7 @@ mod stdack;
6141
mod timestamp;
6242
mod traits;
6343
mod types;
44+
mod utils;
6445

6546
/// This module is to simplify no_std imports
6647
pub(crate) mod prelude;

packages/std/src/query/bank.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::PageRequest;
99
use crate::{Binary, DenomMetadata};
1010

1111
use super::query_response::QueryResponseType;
12+
use crate::utils::impl_hidden_constructor;
1213

1314
#[non_exhaustive]
1415
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

packages/std/src/query/distribution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::prelude::*;
55
use crate::{Addr, Decimal256};
66

77
use super::query_response::QueryResponseType;
8+
use crate::utils::impl_hidden_constructor;
89

910
#[non_exhaustive]
1011
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

packages/std/src/query/ibc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
44
use crate::ibc::IbcChannel;
55
use crate::prelude::*;
66

7+
use crate::utils::impl_hidden_constructor;
8+
79
/// These are queries to the various IBC modules to see the state of the contract's
810
/// IBC connection.
911
/// Most of these will return errors if the contract is not "ibc enabled".

packages/std/src/query/staking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{Addr, Coin, Decimal};
66

77
use super::query_response::QueryResponseType;
88

9+
use crate::utils::impl_hidden_constructor;
10+
911
#[non_exhaustive]
1012
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
1113
#[serde(rename_all = "snake_case")]

packages/std/src/query/wasm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{Addr, Binary, Checksum};
66

77
use super::query_response::QueryResponseType;
88

9+
use crate::utils::impl_hidden_constructor;
10+
911
#[non_exhaustive]
1012
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
1113
#[serde(rename_all = "snake_case")]

packages/std/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::prelude::*;
66
use crate::Binary;
77
use crate::{Addr, Timestamp};
88

9+
use crate::utils::impl_hidden_constructor;
10+
911
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
1012
pub struct Env {
1113
pub block: BlockInfo,

packages/std/src/utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// Implements a hidden constructor for non-exhaustive structures that need
2+
/// to be built in libraries like cw-multi-test.
3+
macro_rules! impl_hidden_constructor {
4+
( $response:ty, $( $field: ident : $t: ty),* ) => {
5+
impl $response {
6+
/// Constructor for testing frameworks such as cw-multi-test.
7+
/// This is required because the type is #[non_exhaustive].
8+
/// As a contract developer you should not need this constructor since
9+
/// the given structure is constructed for you via deserialization.
10+
///
11+
/// Warning: This can change in breaking ways in minor versions.
12+
#[doc(hidden)]
13+
#[allow(dead_code)]
14+
pub fn new($( $field: $t),*) -> Self {
15+
Self { $( $field ),* }
16+
}
17+
}
18+
};
19+
}
20+
21+
pub(crate) use impl_hidden_constructor;

0 commit comments

Comments
 (0)