Skip to content

Commit

Permalink
apply some Vercel suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Jun 11, 2024
1 parent 1237c57 commit 3fe012b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/pages/cw-storage-plus/containers/item.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ An `Item` is a container that stores a single value under a specific key in
storage.

Merely constructing the `Item` object does not commit anything to storage. If an
`Item` has never been written to before, it will be empty.
`Item` has never been written to before (or the value has been
[removed](https://docs.rs/cw-storage-plus/latest/cw_storage_plus/struct.Item.html#method.remove)),
it will be empty.

Under the hood, values are serialized with [`serde`](https://serde.rs/) and
[`serde_json_wasm`](https://docs.rs/serde_json_wasm/).

Use `save` to write to an `Item`.

Expand Down
17 changes: 10 additions & 7 deletions src/pages/cw-storage-plus/containers/map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ trait. Most commonly, the key is simply a `String` or
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.
</Callout>

## Values

The values, as usual, are serialized as JSON and must implement the
Expand Down Expand Up @@ -140,14 +144,13 @@ assert_eq!(alices_balances, vec![("osmo".to_string(), 200), ("uusd".to_string(),

<Callout type="warning">

As seen here, the order of keys isn't always lexicographic. If you need things
ordered, the safe thing to do is to collect them in a vector and `sort` it.
As seen here, the order of keys isn't always lexicographic.

If you'd rather avoid that, here's how things work: under the hood, every
component of a composite key is length-prefixed except for the last one. If
you're only iterating over the last component, you can expect things to be
ordered lexicographically. For non-final components, shorter strings will always
come before longer ones.
If you need to rely on iteration order in maps with composite keys, here's how
things work: under the hood, every component of a composite key is
length-prefixed except for the last one. If you're only iterating over the last
component, you can expect things to be ordered lexicographically. For non-final
components, shorter strings will always come before longer ones.

In the example, note how `"bob"` (a non-last component) comes before `"alice"`.
Also note how once we lock the first component to `"alice"`, entries are ordered
Expand Down

0 comments on commit 3fe012b

Please sign in to comment.