prov_cosmwasm_std/
iterator.rs

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