From 53d0ddac3f49f3d6edf659104e906b71038e03c9 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:44:54 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- src/pages/storey/containers/map.mdx | 42 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/pages/storey/containers/map.mdx b/src/pages/storey/containers/map.mdx index a00b72c1..17eb7af3 100644 --- a/src/pages/storey/containers/map.mdx +++ b/src/pages/storey/containers/map.mdx @@ -8,13 +8,15 @@ import { Callout } from "nextra/components"; A `Map` is a container that maps keys to instances of another container. -Most commonly, you will use a `Map` to store a list of items. For example, the signature could be a `Map>` to store a list of signatures for each user. (See the first example.) +Most commonly, you will use a `Map` to store a list of items. For example, the signature could be a +`Map>` to store a list of signatures for each user. (See the first example.) ## Examples ### Keeping balances -Let's say you want to keep track of the balances of each user. You can do this with a `Map>`. +Let's say you want to keep track of the balances of each user. You can do this with a +`Map>`. ```rust template="storage" showLineNumbers {6,8,10,12,14} use cw_storey::containers::{Item, Map}; @@ -33,17 +35,20 @@ access.entry_mut("alice").set(&Uint128::new(1000)).unwrap(); assert_eq!(access.entry("alice").get().unwrap(), Some(Uint128::new(1000))); ``` -- _line 6:_ Here we construct the `Map` facade. The constructor takes a key, which is the prefix of the keys in the underlying storage backend. +- _line 6:_ Here we construct the `Map` facade. The constructor takes a key, which is the prefix of + the keys in the underlying storage backend. - _line 8:_ The `access` method returns a `MapAccess` entity, which allows manipulating the map. -- _line 10:_ Here we try to access the balance of `alice`. Since she doesn't have one yet, it returns `None`. - The `entry` method returns an `ItemAccess` entity, which allows manipulating the item stored under the key `alice`. +- _line 10:_ Here we try to access the balance of `alice`. Since she doesn't have one yet, it + returns `None`. The `entry` method returns an `ItemAccess` entity, which allows manipulating the + item stored under the key `alice`. - _line 12:_ Here we set Alice's balance to `1000`. - _line 14:_ We check that the balance is now `1000`. #### Iterating over the balances -Iterating over the balances is pretty straightforward. The `keys` method returns an iterator over the keys, -the `values` method returns an iterator over the values, and the `pairs` method returns an iterator over both. +Iterating over the balances is pretty straightforward. The `keys` method returns an iterator over +the keys, the `values` method returns an iterator over the values, and the `pairs` method returns an +iterator over both. ```rust template="storage" showLineNumbers {4, 17, 19} use cw_storey::containers::{Item, Map}; @@ -83,20 +88,20 @@ assert_eq!( - _line 4:_ Here we import the `IterableAccessor` trait. This trait provides unbounded iteration. - _line 17:_ The `pairs` method returns an iterator over the key-value pairs. -- _line 19:_ Notice the key type is `(String, ())`. This is likely to become just `String` in the future. For now, consider this a quirk of the design. This will make more sense once you get to composite maps. - - +- _line 19:_ Notice the key type is `(String, ())`. This is likely to become just `String` in the + future. For now, consider this a quirk of the design. This will make more sense once you get to + composite maps. - When iterating over the entries in a `Map` using these methods, the order of the keys is not guaranteed to be sensible. - Currently if you need a sensible order, try using the bounded iterators instead. If one does not exist, sensibly ordered iteration is not possible. + When iterating over the entries in a `Map` using these methods, the order of the keys is not + guaranteed to be sensible. Currently if you need a sensible order, try using the bounded iterators + instead. If one does not exist, sensibly ordered iteration is not possible. - ### Keeping balances with composition -Alright, let's say this time you'd also like to keep track of the balances of each user, -but each can have multiple different tokens. This is where composition comes in. +Alright, let's say this time you'd also like to keep track of the balances of each user, but each +can have multiple different tokens. This is where composition comes in. ```rust template="storage" showLineNumbers {6, 10-14} use cw_storey::containers::{Item, Map}; @@ -117,9 +122,10 @@ assert_eq!(access.entry("alice").entry("OSMO").get().unwrap(), Some(Uint128::new This example is similar to the previous one, but this time we have an extra level of nesting. -First of all, our type is `Map>>`. -The outer map maps user addresses to an inner map. The inner map maps token denominations to actual balances. +First of all, our type is `Map>>`. The outer map maps user +addresses to an inner map. The inner map maps token denominations to actual balances. -When we access the stuff, the first `entry`/`entry_mut` call accesses a record in the outer map, and the second one accesses a record in the inner map. +When we access the stuff, the first `entry`/`entry_mut` call accesses a record in the outer map, and +the second one accesses a record in the inner map. #### Iterating over the balances