1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
use crate::action::ZomeId;
use crate::zome::ZomeName;
use crate::EntryDefIndex;
use crate::EntryDefs;
use crate::FunctionName;
use crate::LinkType;
use holo_hash::DnaHash;
use holochain_serialized_bytes::prelude::*;
#[cfg(test)]
mod test;
#[allow(missing_docs)]
#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq)]
pub struct ZomeInfo {
pub name: ZomeName,
pub id: ZomeId,
pub properties: SerializedBytes,
pub entry_defs: EntryDefs,
pub extern_fns: Vec<FunctionName>,
pub zome_types: ScopedZomeTypesSet,
}
impl ZomeInfo {
pub fn new(
name: ZomeName,
id: ZomeId,
properties: SerializedBytes,
entry_defs: EntryDefs,
extern_fns: Vec<FunctionName>,
zome_types: ScopedZomeTypesSet,
) -> Self {
Self {
name,
id,
properties,
entry_defs,
extern_fns,
zome_types,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DnaInfo {
pub name: String,
pub hash: DnaHash,
pub properties: SerializedBytes,
pub zome_names: Vec<ZomeName>,
}
#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq, Default)]
pub struct ScopedZomeTypesSet {
pub entries: ScopedZomeTypes<EntryDefIndex>,
pub links: ScopedZomeTypes<LinkType>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ScopedZomeTypes<T>(pub Vec<(ZomeId, Vec<T>)>);
impl<T> Default for ScopedZomeTypes<T> {
fn default() -> Self {
Self(Default::default())
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ZomeTypesKey<T>
where
T: U8Index + Copy,
{
pub zome_index: ZomeDependencyIndex,
pub type_index: T,
}
pub type ZomeEntryTypesKey = ZomeTypesKey<EntryDefIndex>;
pub type ZomeLinkTypesKey = ZomeTypesKey<LinkType>;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ZomeDependencyIndex(pub u8);
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ScopedZomeType<T> {
pub zome_id: ZomeId,
pub zome_type: T,
}
pub type ScopedEntryDefIndex = ScopedZomeType<EntryDefIndex>;
pub type ScopedLinkType = ScopedZomeType<LinkType>;
impl<T> ScopedZomeTypes<T>
where
T: U8Index + Copy,
{
pub fn get<K>(&self, key: K) -> Option<ScopedZomeType<T>>
where
K: Into<ZomeTypesKey<T>>,
{
let key = key.into();
self.0
.get(key.zome_index.index())
.and_then(|(zome_id, types)| {
types
.get(key.type_index.index())
.copied()
.map(|zome_type| ScopedZomeType {
zome_id: *zome_id,
zome_type,
})
})
}
pub fn find<I, K>(&self, iter: I, scoped_type: ScopedZomeType<T>) -> Option<I::Item>
where
I: IntoIterator<Item = K>,
K: Into<ZomeTypesKey<T>> + Copy,
T: PartialEq,
{
iter.into_iter()
.find_map(|key| (self.get(key)? == scoped_type).then(|| key))
}
pub fn find_key(&self, scoped_type: ScopedZomeType<T>) -> Option<ZomeTypesKey<T>>
where
T: PartialEq,
T: From<u8>,
{
self.0
.iter()
.position(|(zome_id, _)| *zome_id == scoped_type.zome_id)
.and_then(|zome_index| {
self.0[zome_index]
.1
.iter()
.position(|zome_type| *zome_type == scoped_type.zome_type)
.and_then(|type_index| {
Some(ZomeTypesKey {
zome_index: u8::try_from(zome_index).ok()?.into(),
type_index: u8::try_from(type_index).ok()?.into(),
})
})
})
}
pub fn dependencies(&self) -> impl Iterator<Item = ZomeId> + '_ {
self.0.iter().map(|(zome_id, _)| *zome_id)
}
}
impl From<EntryDefIndex> for ZomeEntryTypesKey {
fn from(type_index: EntryDefIndex) -> Self {
Self {
zome_index: 0.into(),
type_index,
}
}
}
impl From<LinkType> for ZomeLinkTypesKey {
fn from(type_index: LinkType) -> Self {
Self {
zome_index: 0.into(),
type_index,
}
}
}
#[doc(hidden)]
pub trait EnumLen {
const ENUM_LEN: u8;
}
#[doc(hidden)]
pub trait EnumVariantLen<const V: u8> {
const ENUM_VARIANT_START: u8;
const ENUM_VARIANT_INNER_LEN: u8;
const ENUM_VARIANT_LEN: u8 = Self::ENUM_VARIANT_START + Self::ENUM_VARIANT_INNER_LEN;
}
pub trait U8Index {
fn index(&self) -> usize;
}
impl U8Index for ZomeDependencyIndex {
fn index(&self) -> usize {
self.0 as usize
}
}
impl U8Index for EntryDefIndex {
fn index(&self) -> usize {
self.0 as usize
}
}
impl U8Index for LinkType {
fn index(&self) -> usize {
self.0 as usize
}
}
impl From<u8> for ZomeDependencyIndex {
fn from(v: u8) -> Self {
Self(v)
}
}