Skip to content

Commit cc71eae

Browse files
authored
Merge pull request #2197 from CosmWasm/co/iterator-default-impl
Add default impl for `Storage::range`
2 parents a106547 + adc9fd1 commit cc71eae

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ and this project adheres to
1212

1313
- cosmwasm-std: Make fields of `IbcAckCallbackMsg` and `IbcTimeoutCallbackMsg`
1414
public. ([#2191])
15+
- cosmwasm-std: Add default implementation for `Storage::range` to make
16+
`iterator` feature additive. ([#2197])
1517

1618
[#2191]: https://github.com/CosmWasm/cosmwasm/pull/2191
19+
[#2197]: https://github.com/CosmWasm/cosmwasm/pull/2197
1720

1821
## [2.1.0] - 2024-07-11
1922

packages/std/src/traits.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ pub trait Storage {
6161
/// The bound `start` is inclusive and `end` is exclusive.
6262
/// If `start` is lexicographically greater than or equal to `end`, an empty range is described, mo matter of the order.
6363
#[cfg(feature = "iterator")]
64+
#[allow(unused_variables)]
6465
fn range<'a>(
6566
&'a self,
6667
start: Option<&[u8]>,
6768
end: Option<&[u8]>,
6869
order: Order,
69-
) -> Box<dyn Iterator<Item = Record> + 'a>;
70+
) -> Box<dyn Iterator<Item = Record> + 'a> {
71+
// This default implementation is just to avoid breaking code when enabling the `iterator` feature.
72+
// Any actual `Storage` impl should override this method.
73+
unimplemented!("This storage does not support ranging. Make sure to override the `range` method in your `Storage` implementation.")
74+
}
7075

7176
/// Allows iteration over a set of keys, either forwards or backwards.
7277
///

0 commit comments

Comments
 (0)