Skip to content

Commit 63a074f

Browse files
[autofix.ci] apply automated fixes
1 parent 850575c commit 63a074f

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

src/pages/storey/container-impl.mdx

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { Callout } from "nextra/components";
66

77
# Implementing new containers
88

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`].
1113

1214
# MyMap
1315

@@ -33,12 +35,15 @@ impl<V> MyMap<V> {
3335
}
3436
```
3537

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.
3740

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.
3943

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.
4247

4348
The constructor is simple - it just initializes the fields.
4449

@@ -105,30 +110,33 @@ where
105110

106111
Whew. Let's break this down.
107112

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:
112-
| Associated type | Details |
113-
|-------------------|-------------------------------------------------------------------------|
114-
| `Kind` | We put `NonTerminal` here to signify our container creates subkeys rather than just saving data at the root. |
115-
| `Accessor` | The accessor type. `MyMapAccess` in our case. |
116-
| `Key` | The key type to be returned by iterators. Here a tuple of `u32` and the key type of the inner container. |
117-
| `KeyDecodeError` | The error to be returned on invalid key data. Here we don't care, so we use `()`. In production, use a proper error type. |
118-
| `Value` | The value type to be returned by iterators. Here it's delegated to the inner container. |
119-
| `ValueDecodeError`| The error type for invalid value data. Delegated to the inner container. |
120-
121-
The methods:
122-
| Method | Function |
123-
|----------------|-----------------------------------------------------------------------------|
124-
| `access_impl` | Produces an accessor given a storage abstraction (usually representing a "slice" of the underlying storage.) |
125-
| `decode_key` | Used for iteration. This is how the framework knows how to decode this map's keys given raw data from the storage backend. |
126-
| `decode_value` | Used for iteration. This is how the framework knows how to decode values given raw data. |
127-
128-
`MyMap::access` is an access method in cases where you're using the container as a top-level container.
129-
130-
There's one thing we're missing for this to actually by useful. We need some methods
131-
for the accessor.
113+
The `MyMapAccess` struct is our accessor. It's a facade that's used to actually access the data in
114+
the collection given a `Storage` instance - this is usually a subspace of the "root" storage
115+
backend.
116+
117+
The [`Storable`] trait is the main trait a container must implement. It's currently a mix of things.
118+
The associated types tell the framework: | Associated type | Details |
119+
|-------------------|-------------------------------------------------------------------------| |
120+
`Kind` | We put `NonTerminal` here to signify our container creates subkeys rather than just saving
121+
data at the root. | | `Accessor` | The accessor type. `MyMapAccess` in our case. | | `Key` | The key
122+
type to be returned by iterators. Here a tuple of `u32` and the key type of the inner container. | |
123+
`KeyDecodeError` | The error to be returned on invalid key data. Here we don't care, so we use `()`.
124+
In production, use a proper error type. | | `Value` | The value type to be returned by iterators.
125+
Here it's delegated to the inner container. | | `ValueDecodeError`| The error type for invalid value
126+
data. Delegated to the inner container. |
127+
128+
The methods: | Method | Function |
129+
|----------------|-----------------------------------------------------------------------------| |
130+
`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.
132140

133141
```rust template="storage" {2, 59-78}
134142
use storey::containers::{NonTerminal, Storable};
@@ -207,8 +215,9 @@ where
207215
}
208216
```
209217

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`.
212221

213222
Time to see this in action.
214223

@@ -238,4 +247,4 @@ To be continued...
238247
[`Item`]: /storey/containers/item
239248
[`Map`]: /storey/containers/map
240249
[`Storable`]: https://docs.rs/storey/latest/storey/containers/trait.Storable.html
241-
[`StorageBranch`]: https://docs.rs/storey/latest/storey/storage/struct.StorageBranch.html
250+
[`StorageBranch`]: https://docs.rs/storey/latest/storey/storage/struct.StorageBranch.html

0 commit comments

Comments
 (0)