You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/storey/container-impl.mdx
+42-33Lines changed: 42 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,10 @@ import { Callout } from "nextra/components";
6
6
7
7
# Implementing new containers
8
8
9
-
Storey provides a set of built-in containers, but you're not limited to just those. For special needs, you can go ahead and create your own containers that will
10
-
play along nicely with the rest of the Storey "ecosystem". If it's appropriate, your container could for example allow for nesting other containers - like [`Map`].
9
+
Storey provides a set of built-in containers, but you're not limited to just those. For special
10
+
needs, you can go ahead and create your own containers that will play along nicely with the rest of
11
+
the Storey "ecosystem". If it's appropriate, your container could for example allow for nesting
12
+
other containers - like [`Map`].
11
13
12
14
# MyMap
13
15
@@ -33,12 +35,15 @@ impl<V> MyMap<V> {
33
35
}
34
36
```
35
37
36
-
No magic here. The `prefix` field is used when this collection is a top-level collection - it's a single-byte key that creates a subspace for this collection's internal data.
38
+
No magic here. The `prefix` field is used when this collection is a top-level collection - it's a
39
+
single-byte key that creates a subspace for this collection's internal data.
37
40
38
-
The `phantom` field allows us to use the type parameter `V` without actually storing any values of that type.
41
+
The `phantom` field allows us to use the type parameter `V` without actually storing any values of
42
+
that type.
39
43
40
-
The `V` type parameter is the type of the **container** inside the map. If you've followed the [`Map`] documentation,
41
-
you'll know that `Map` is a composable container - it holds another container inside.
44
+
The `V` type parameter is the type of the **container** inside the map. If you've followed the
45
+
[`Map`] documentation, you'll know that `Map` is a composable container - it holds another container
46
+
inside.
42
47
43
48
The constructor is simple - it just initializes the fields.
44
49
@@ -105,30 +110,33 @@ where
105
110
106
111
Whew. Let's break this down.
107
112
108
-
The `MyMapAccess` struct is our accessor. It's a facade that's used to actually
109
-
access the data in the collection given a `Storage` instance - this is usually a subspace of the "root" storage backend.
110
-
111
-
The [`Storable`] trait is the main trait a container must implement. It's currently a mix of things. The associated types tell the framework:
`access_impl` | Produces an accessor given a storage abstraction (usually representing a "slice" of
131
+
the underlying storage.) | | `decode_key` | Used for iteration. This is how the framework knows how
132
+
to decode this map's keys given raw data from the storage backend. | | `decode_value` | Used for
133
+
iteration. This is how the framework knows how to decode values given raw data. |
134
+
135
+
`MyMap::access` is an access method in cases where you're using the container as a top-level
136
+
container.
137
+
138
+
There's one thing we're missing for this to actually by useful. We need some methods for the
139
+
accessor.
132
140
133
141
```rust template="storage" {2, 59-78}
134
142
usestorey::containers::{NonTerminal, Storable};
@@ -207,8 +215,9 @@ where
207
215
}
208
216
```
209
217
210
-
What does this new code do? It provides a way to create accessors for the inner container based on the `u32` key.
211
-
The [`StorageBranch`] type is a helper that creates a "subspace" of the storage backend. It's used to create a "slice" of the storage granted to `MyMap`.
218
+
What does this new code do? It provides a way to create accessors for the inner container based on
219
+
the `u32` key. The [`StorageBranch`] type is a helper that creates a "subspace" of the storage
220
+
backend. It's used to create a "slice" of the storage granted to `MyMap`.
0 commit comments