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::linked_table::LinkedTable type.
63#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
64pub struct LinkedTable<K> {
65    pub id: ObjectId,
66    pub size: u64,
67    pub head: Option<K>,
68    pub tail: Option<K>,
69}
70
71impl<K> Default for LinkedTable<K> {
72    fn default() -> Self {
73        LinkedTable {
74            id: ObjectId::ZERO,
75            size: 0,
76            head: None,
77            tail: None,
78        }
79    }
80}
81
82/// Rust version of the Move iota::linked_table::Node type.
83#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
84pub struct LinkedTableNode<K, V> {
85    pub prev: Option<K>,
86    pub next: Option<K>,
87    pub value: V,
88}
89
90/// Rust version of the Move iota::bag::Bag type.
91#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
92pub struct Bag {
93    pub id: UID,
94    pub size: u64,
95}
96
97impl Default for Bag {
98    fn default() -> Self {
99        Self {
100            id: UID::new(ObjectId::ZERO),
101            size: 0,
102        }
103    }
104}