@@ -24,43 +24,39 @@ This change will also break existing contracts that rely on the current `Column`
24
24
25
25
Let's say you want to store a log of messages. You can do this with a ` Column<String> ` .
26
26
27
- ``` rust template="storage" showLineNumbers {6,8,10,12 }
27
+ ``` rust template="storage" showLineNumbers {5, 6,8,10}
28
28
use cw_storey :: containers :: Column ;
29
- use cw_storey :: CwStorage ;
30
29
31
30
const MESSAGES_IX : u8 = 1 ;
32
31
33
32
let messages : Column <String > = Column :: new (MESSAGES_IX );
34
- let mut cw_storage = CwStorage (& mut storage );
35
- let mut access = messages . access (& mut cw_storage );
33
+ let mut access = messages . access (& mut storage );
36
34
37
35
access . push (& " Hello, world!" . to_string ()). unwrap ();
38
36
39
- assert_eq! (access . get (0 ). unwrap (), Some (" Hello, world!" . to_string ()));
37
+ assert_eq! (access . get (1 ). unwrap (), Some (" Hello, world!" . to_string ()));
40
38
```
41
39
42
- - _ line 6 :_ Here we construct the ` Column ` facade. The constructor takes a key, which is the prefix
40
+ - _ line 5 :_ Here we construct the ` Column ` facade. The constructor takes a key, which is the prefix
43
41
of the keys in the underlying storage backend.
44
- - _ line 8 :_ The [ ` access ` ] method returns a [ ` ColumnAccess ` ] entity, which allows manipulating the
42
+ - _ line 6 :_ The [ ` access ` ] method returns a [ ` ColumnAccess ` ] entity, which allows manipulating the
45
43
column.
46
- - _ line 10 :_ Here we push a message to the column.
47
- - _ line 12 :_ We check that the message is stored correctly.
44
+ - _ line 8 :_ Here we push a message to the column.
45
+ - _ line 10 :_ We check that the message is stored correctly.
48
46
49
47
#### Iterating over the messages
50
48
51
49
As with [ ` Map ` ] , we can iterate over all messages.
52
50
53
- ``` rust template="storage" showLineNumbers {4, 17 }
51
+ ``` rust template="storage" showLineNumbers {3, 15 }
54
52
use cw_storey :: containers :: {Column , Item };
55
- use cw_storey :: CwStorage ;
56
53
57
54
use storey :: containers :: IterableAccessor as _;
58
55
59
56
const MESSAGES_IX : u8 = 1 ;
60
57
61
58
let messages : Column <String > = Column :: new (MESSAGES_IX );
62
- let mut cw_storage = CwStorage (& mut storage );
63
- let mut access = messages . access (& mut cw_storage );
59
+ let mut access = messages . access (& mut storage );
64
60
65
61
// populate the column
66
62
access . push (& " Hello, world!" . to_string ()). unwrap ();
@@ -70,14 +66,14 @@ access.push(&"Hell is empty and all the devils are here.".to_string()).unwrap();
70
66
let messages : Vec <_ > = access . pairs (). collect :: <Result <_ , _ >>(). unwrap ();
71
67
72
68
assert_eq! (messages , vec! [
73
- (0 , " Hello, world!" . to_string ()),
74
- (1 , " My name is Bob." . to_string ()),
75
- (2 , " Hell is empty and all the devils are here." . to_string ()),
69
+ (1 , " Hello, world!" . to_string ()),
70
+ (2 , " My name is Bob." . to_string ()),
71
+ (3 , " Hell is empty and all the devils are here." . to_string ()),
76
72
]);
77
73
```
78
74
79
- - _ line 4 :_ We import the ` IterableAccessor ` trait to use iteration methods.
80
- - _ line 17 :_ The ` pairs ` method produces an iterator over tuples of ` (index, value) ` . In this case,
75
+ - _ line 3 :_ We import the ` IterableAccessor ` trait to use iteration methods.
76
+ - _ line 15 :_ The ` pairs ` method produces an iterator over tuples of ` (index, value) ` . In this case,
81
77
we collect the iterator into a ` Vec ` for ease of making our assertion later.
82
78
83
79
Similarly to [ ` Map ` ] , you can use the [ ` keys ` ] , [ ` values ` ] , and [ ` pairs ` ] methods to iterate over
@@ -89,7 +85,7 @@ If you want to perform bounded iteration, it is possible. This time you need the
89
85
[ ` BoundedIterableAccessor ` ] trait, and the relevant methods are [ ` bounded_pairs ` ] , [ ` bounded_keys ` ] ,
90
86
and [ ` bounded_values ` ] .
91
87
92
- The following example is the same as the previous one except for the bounds found in line 17 , and
88
+ The following example is the same as the previous one except for the bounds found in line 16 , and
93
89
the limited results.
94
90
95
91
<Callout >
@@ -100,28 +96,27 @@ bounds as suits you.
100
96
101
97
</Callout >
102
98
103
- ``` rust template="storage" showLineNumbers {4, 17}
104
- use cw_storey :: containers :: {Column , Item };
105
- use cw_storey :: CwStorage ;
99
+ ``` rust template="storage" showLineNumbers {4, 16}
100
+ use std :: ops :: Bound ;
106
101
102
+ use cw_storey :: containers :: {Column , Item };
107
103
use storey :: containers :: BoundedIterableAccessor as _;
108
104
109
105
const MESSAGES_IX : u8 = 1 ;
110
106
111
107
let messages : Column <String > = Column :: new (MESSAGES_IX );
112
- let mut cw_storage = CwStorage (& mut storage );
113
- let mut access = messages . access (& mut cw_storage );
108
+ let mut access = messages . access (& mut storage );
114
109
115
110
// populate the column
116
111
access . push (& " Hello, world!" . to_string ()). unwrap ();
117
112
access . push (& " My name is Bob." . to_string ()). unwrap ();
118
113
access . push (& " Hell is empty and all the devils are here." . to_string ()). unwrap ();
119
114
120
- let messages : Vec <_ > = access . bounded_pairs (Some ( 0 ), Some ( 2 )). collect :: <Result <_ , _ >>(). unwrap ();
115
+ let messages : Vec <_ > = access . bounded_pairs (Bound :: Included ( 1 ), Bound :: Excluded ( 3 )). collect :: <Result <_ , _ >>(). unwrap ();
121
116
122
117
assert_eq! (messages , vec! [
123
- (0 , " Hello, world!" . to_string ()),
124
- (1 , " My name is Bob." . to_string ()),
118
+ (1 , " Hello, world!" . to_string ()),
119
+ (2 , " My name is Bob." . to_string ()),
125
120
]);
126
121
```
127
122
0 commit comments