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 serde::{Deserialize, Serialize};
6
7use crate::{base_types::ObjectID, id::UID};
8
9/// Rust version of the Move iota::vec_map::VecMap type
10#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
11pub struct VecMap<K, V> {
12    pub contents: Vec<Entry<K, V>>,
13}
14
15/// Rust version of the Move iota::vec_map::Entry type
16#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
17pub struct Entry<K, V> {
18    pub key: K,
19    pub value: V,
20}
21
22/// Rust version of the Move iota::vec_set::VecSet type
23#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
24pub struct VecSet<T> {
25    pub contents: Vec<T>,
26}
27
28/// Rust version of the Move iota::table::Table type.
29#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
30pub struct TableVec {
31    pub contents: Table,
32}
33
34impl Default for TableVec {
35    fn default() -> Self {
36        TableVec {
37            contents: Table {
38                id: ObjectID::ZERO,
39                size: 0,
40            },
41        }
42    }
43}
44
45/// Rust version of the Move iota::table::Table type.
46#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
47pub struct Table {
48    pub id: ObjectID,
49    pub size: u64,
50}
51
52impl Default for Table {
53    fn default() -> Self {
54        Table {
55            id: ObjectID::ZERO,
56            size: 0,
57        }
58    }
59}
60
61/// Rust version of the Move iota::linked_table::LinkedTable type.
62#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
63pub struct LinkedTable<K> {
64    pub id: ObjectID,
65    pub size: u64,
66    pub head: Option<K>,
67    pub tail: Option<K>,
68}
69
70impl<K> Default for LinkedTable<K> {
71    fn default() -> Self {
72        LinkedTable {
73            id: ObjectID::ZERO,
74            size: 0,
75            head: None,
76            tail: None,
77        }
78    }
79}
80
81/// Rust version of the Move iota::linked_table::Node type.
82#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
83pub struct LinkedTableNode<K, V> {
84    pub prev: Option<K>,
85    pub next: Option<K>,
86    pub value: V,
87}
88
89/// Rust version of the Move iota::bag::Bag type.
90#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
91pub struct Bag {
92    pub id: UID,
93    pub size: u64,
94}
95
96impl Default for Bag {
97    fn default() -> Self {
98        Self {
99            id: UID::new(ObjectID::ZERO),
100            size: 0,
101        }
102    }
103}