WEBVTT

00:00:00.500 --> 00:00:03.924
For saved fields, start with the SDK's collections.

00:00:04.825 --> 00:00:06.752
Map looks up entries by key.

00:00:07.650 --> 00:00:09.590
Vec keeps a list you can index.

00:00:10.489 --> 00:00:12.950
Queue lets you add and remove at either end.

00:00:13.848 --> 00:00:17.481
These values can be kept between calls and across upgrades.

00:00:18.379 --> 00:00:21.765
Inventory needs to find an item by its number, so it saves a

00:00:21.778 --> 00:00:24.499
map from item number to a small Item struct.

00:00:25.397 --> 00:00:28.913
The struct derives Nyxus data, which is what lets it be a saved

00:00:28.926 --> 00:00:29.408
value.

00:00:30.306 --> 00:00:33.496
Code under the module reads and changes entries with ordinary

00:00:33.509 --> 00:00:34.421
map methods.

00:00:35.319 --> 00:00:37.585
A map will keep growing if the code lets it.

00:00:38.483 --> 00:00:41.830
Inventory decides that a branch holds at most one thousand and

00:00:41.843 --> 00:00:44.981
twenty-four items and refuses a new one past that.

00:00:45.879 --> 00:00:48.783
The limit is the application's choice and the application's

00:00:48.796 --> 00:00:49.304
code.

00:00:51.433 --> 00:00:53.386
A larger app has a different need.

00:00:54.286 --> 00:00:58.062
Heavy16 gives every accepted request a receipt number and starts

00:00:58.075 --> 00:00:59.312
them in arrival order.

00:01:00.211 --> 00:01:03.440
It saves a Vec of entries and one cursor for the next request

00:01:03.453 --> 00:01:04.091
to start.

00:01:04.989 --> 00:01:07.164
A receipt number is a position in the list.

00:01:08.062 --> 00:01:10.601
Two constants cap the total and the number waiting.

00:01:11.500 --> 00:01:14.521
An ordinary Rust String or Vec is a transient value.

00:01:15.419 --> 00:01:19.065
To put one in saved data, convert it to a supported type.

00:01:19.963 --> 00:01:23.791
Here Heavy16 turns an ordinary byte vector into a saved one

00:01:23.804 --> 00:01:24.885
with from transient.

00:01:27.000 --> 00:01:29.070
The third case is from the last lesson.

00:01:29.970 --> 00:01:33.187
Each branch has its own inventory, with its own rules and its

00:01:33.200 --> 00:01:36.728
own limit, and it should vanish as a whole when the branch closes.

00:01:37.627 --> 00:01:41.116
That is a child module per key, and the type for it is Child

00:01:41.129 --> 00:01:41.481
Map.

00:01:42.379 --> 00:01:46.194
Map and Set keep their keys in order, so you can ask for a range.

00:01:47.093 --> 00:01:50.439
To page through a map, return a limited number of rows and the

00:01:50.452 --> 00:01:51.194
last key.

00:01:52.093 --> 00:01:55.140
The next call uses that key to start the next range.

00:01:57.267 --> 00:02:00.964
Everything so far used the default engine, Nyxus, which keeps

00:02:00.977 --> 00:02:02.514
ordinary Rust values.

00:02:03.414 --> 00:02:06.995
A module can choose Hylix, which keeps its record in stable

00:02:07.008 --> 00:02:07.425
memory.

00:02:08.323 --> 00:02:11.266
The choice is one word on the memory attribute and it covers

00:02:11.279 --> 00:02:13.180
that module's whole Data record.

00:02:14.079 --> 00:02:17.177
Hylix has its own collections with the same names and different

00:02:17.190 --> 00:02:17.894
derives.

00:02:18.792 --> 00:02:20.967
The two engines ask different things of you.

00:02:21.865 --> 00:02:23.779
With Nyxus you write normal Rust.

00:02:24.677 --> 00:02:28.115
With Hylix, a read gives you a copy, and when you remove or

00:02:28.128 --> 00:02:31.605
replace a saved value you must move it or retire it yourself.

00:02:32.503 --> 00:02:35.341
One app can use both, each in its own module.

00:02:36.240 --> 00:02:39.352
Choose per module from how the data is used, and measure the

00:02:39.365 --> 00:02:41.852
real application before deciding on speed.

00:02:42.750 --> 00:02:46.058
The example on the right uses an experimental Minima collection

00:02:46.071 --> 00:02:47.894
for a fixed-width lookup index.

00:02:48.792 --> 00:02:51.331
Readers use one built index at a time.

00:02:52.230 --> 00:02:55.537
To publish changed entries, build a replacement index.

00:02:56.435 --> 00:02:58.532
That fits data you refresh as a set.

00:02:59.430 --> 00:03:02.855
For item stock you edit one entry at a time, keep the Shop's

00:03:02.868 --> 00:03:03.271
Map.

