cosmwasm_std/
iterator.rs

1use crate::errors::StdError;
2
3/// A record of a key-value storage that is created through an iterator API.
4/// The first element (key) is always raw binary data. The second element
5/// (value) is binary by default but can be changed to a custom type. This
6/// allows contracts to reuse the type when deserializing database records.
7pub type Record<V = Vec<u8>> = (Vec<u8>, V);
8
9#[derive(Copy, Clone, PartialEq, Eq)]
10// We assign these to integers to provide a stable API for passing over FFI (to wasm and Go)
11pub enum Order {
12    Ascending = 1,
13    Descending = 2,
14}
15
16impl TryFrom<i32> for Order {
17    type Error = StdError;
18
19    fn try_from(value: i32) -> Result<Self, Self::Error> {
20        match value {
21            1 => Ok(Order::Ascending),
22            2 => Ok(Order::Descending),
23            _ => Err(StdError::generic_err("Order must be 1 or 2")),
24        }
25    }
26}
27
28impl From<Order> for i32 {
29    fn from(original: Order) -> i32 {
30        original as _
31    }
32}