jk_cosmwasm_std/
iterator.rs

1use crate::errors::StdError;
2use std::convert::TryFrom;
3
4/// A Key-Value pair, returned from our iterators
5pub type Pair<V = Vec<u8>> = (Vec<u8>, V);
6
7/// KV is a Key-Value pair, returned from our iterators
8#[deprecated(since = "0.14.0", note = "Renamed to Pair")]
9#[allow(clippy::upper_case_acronyms)]
10pub type KV<V = Vec<u8>> = Pair<V>;
11
12#[derive(Copy, Clone)]
13// We assign these to integers to provide a stable API for passing over FFI (to wasm and Go)
14pub enum Order {
15    Ascending = 1,
16    Descending = 2,
17}
18
19impl TryFrom<i32> for Order {
20    type Error = StdError;
21
22    fn try_from(value: i32) -> Result<Self, Self::Error> {
23        match value {
24            1 => Ok(Order::Ascending),
25            2 => Ok(Order::Descending),
26            _ => Err(StdError::generic_err("Order must be 1 or 2")),
27        }
28    }
29}
30
31impl From<Order> for i32 {
32    fn from(original: Order) -> i32 {
33        original as _
34    }
35}