Skip to main content

iota_types/
collection_types.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_sdk_types::ObjectId;
6use serde::{Deserialize, Serialize};
7
8use crate::id::UID;
9
10/// Rust version of the Move iota::vec_map::VecMap type
11#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
12pub struct VecMap<K, V> {
13    pub contents: Vec<Entry<K, V>>,
14}
15
16/// Rust version of the Move iota::vec_map::Entry type
17#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
18pub struct Entry<K, V> {
19    pub key: K,
20    pub value: V,
21}
22
23/// Rust version of the Move iota::vec_set::VecSet type
24#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
25pub struct VecSet<T> {
26    pub contents: Vec<T>,
27}
28
29/// Rust version of the Move iota::table::Table type.
30#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
31pub struct TableVec {
32    pub contents: Table,
33}
34
35impl Default for TableVec {
36    fn default() -> Self {
37        TableVec {
38            contents: Table {
39                id: ObjectId::ZERO,
40                size: 0,
41            },
42        }
43    }
44}
45
46/// Rust version of the Move iota::table::Table type.
47#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
48pub struct Table {
49    pub id: ObjectId,
50    pub size: u64,
51}
52
53impl Default for Table {
54    fn default() -> Self {
55        Table {
56            id: ObjectId::ZERO,
57            size: 0,
58        }
59    }
60}
61
62/// Rust version of the Move iota::bag::Bag type.
63#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
64pub struct Bag {
65    pub id: UID,
66    pub size: u64,
67}
68
69impl Default for Bag {
70    fn default() -> Self {
71        Self {
72            id: UID::new(ObjectId::ZERO),
73            size: 0,
74        }
75    }
76}