Skip to content

Commit

Permalink
Merge pull request #81 from CosmWasm/aw/add-tags-storage
Browse files Browse the repository at this point in the history
Add tags across storage-plus section
  • Loading branch information
aumetra authored Jul 1, 2024
2 parents ae1d47e + f98e4f5 commit bdbdf0b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus"]
---

# Introduction

Not being able to persist data across calls would limit the utility of smart
Expand Down
8 changes: 6 additions & 2 deletions src/pages/cw-storage-plus/basics.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "basics"]
---

import { Callout } from "nextra/components";

# Basics
Expand Down Expand Up @@ -51,8 +55,8 @@ better advice.
is saved without any sort of length-prefixing of the key. It is, in theory,
possible for an `Item`'s key to conflict with one of the keys generated by a
`Map` or `Deque`. In practice, this is unlikely unless you use very long
prefixes or start your `Item`'s key with the null byte. Probably don't
do that!
prefixes or start your `Item`'s key with the null byte. Probably don't do
that!
</Callout>

## Values
Expand Down
6 changes: 5 additions & 1 deletion src/pages/cw-storage-plus/containers/deque.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "containers"]
---

import { Callout } from "nextra/components";

# `Deque`
Expand Down Expand Up @@ -27,7 +31,7 @@ the deque, [`get`] an element by index, and [`iter`]ate over the elements.

<Callout type="warning">
The maximum capacity of a `Deque` is `u32::MAX - 1` elements. Trying to push
more elements is considered Undefined Behavior💀.
more elements is considered Undefined Behavior💀.
</Callout>

More information can be found in the
Expand Down
29 changes: 18 additions & 11 deletions src/pages/cw-storage-plus/containers/indexed-map.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "containers"]
---

import { Callout } from "nextra/components";

# IndexedMap
Expand All @@ -8,9 +12,9 @@ is a map that, apart from the usual map key `K` has some secondary indexes `I`
that can be used to look up values.

<Callout>
There's no limit to how many indexes you can have, but be careful. Using many indexes can increase the complexity of
storage writes - with every write, the list of indexes is iterated over since
they might need to be updated.
There's no limit to how many indexes you can have, but be careful. Using many
indexes can increase the complexity of storage writes - with every write, the
list of indexes is iterated over since they might need to be updated.
</Callout>

As always, we encourage you to explore the
Expand All @@ -26,8 +30,9 @@ users by their address - if Alice calls the contract, we should be able to look
up her user data by the address with which she called.

<Callout>
Every snippet on this page builds on the previous ones. Make sure you've
understood the previous snippet before moving on to the next one, and feel free to go back and forth as needed.
Every snippet on this page builds on the previous ones. Make sure you've
understood the previous snippet before moving on to the next one, and feel
free to go back and forth as needed.
</Callout>

This is easy to model with a normal `Map`.
Expand Down Expand Up @@ -72,9 +77,10 @@ let _users = IndexedMap::<Addr, _, _>::new("u", user_indexes);
```

<Callout>
The `index_list` macro is used to define a list of indexes for a given struct.
The `index_list` macro is used to define a list of indexes for a given struct.
This is a helper macro that generates an implementation of the
[`IndexList`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/trait.IndexList.html) trait, with all the fields of the struct as indexes.
[`IndexList`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/trait.IndexList.html)
trait, with all the fields of the struct as indexes.
</Callout>

Here's what happens step-by-step
Expand Down Expand Up @@ -102,13 +108,14 @@ Here's what happens step-by-step
</Callout>

<Callout type="warning">
If you're using
If you're using
[`UniqueIndex`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.UniqueIndex.html),
it's your responsibility to ensure that the index you've built has unique
keys. If you have two users with the same handle, the index will be
overwritten and only contain the last user. Be careful!

If you need to store a key that is not unique, you'll want to use a [`MultiIndex`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.MultiIndex.html) - see the [next section](#lookup-by-country).
overwritten and only contain the last user. Be careful! If you need to store a
key that is not unique, you'll want to use a
[`MultiIndex`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.MultiIndex.html)
- see the [next section](#lookup-by-country).
</Callout>

<Callout>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/cw-storage-plus/containers/item.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "containers"]
---

# `Item`

An `Item` is a container that stores a single value under a specific key in
Expand Down
11 changes: 9 additions & 2 deletions src/pages/cw-storage-plus/containers/map.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "containers"]
---

import { Callout } from "nextra/components";

# `Map`
Expand All @@ -15,7 +19,9 @@ Other types include binary strings (`Vec<u8>`, `[u8; N]`, `&[u8]`), numerical
types, or even tuples, which can be used to create composite keys.

<Callout>
Unlike values, keys do **not** need to implement anything like `serde::Serialize` or `serde::Deserialize`. Key encoding is handled by the `PrimaryKey` trait.
Unlike values, keys do **not** need to implement anything like
`serde::Serialize` or `serde::Deserialize`. Key encoding is handled by the
`PrimaryKey` trait.
</Callout>

## Values
Expand All @@ -36,7 +42,8 @@ or
[`range`](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.Map.html#method.range).

<Callout>
[For each bound, it's possible to decide if it's meant to be inclusive or exclusive.](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/enum.Bound.html)
[For each bound, it's possible to decide if it's meant to be inclusive or
exclusive.](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/enum.Bound.html)
</Callout>

More information can be found in the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "multi-indexes"]
---

# Multi index collections

TODO: bonus section, maybe flesh out, maybe remove
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
tags: ["storage-plus", "snapshots"]
---

# Snapshots

TODO: bonus section, maybe flesh out, maybe remove

0 comments on commit bdbdf0b

Please sign in to comment.