WEBVTT

00:00:00.500 --> 00:00:03.911
This is Quickstart, a complete canister that saves scores.

00:00:04.812 --> 00:00:07.194
Its public methods are in lib dot r s.

00:00:08.093 --> 00:00:10.124
The scores feature has its own folder.

00:00:11.022 --> 00:00:13.887
The root folder wires the app together at startup.

00:00:14.785 --> 00:00:18.522
Inside a feature folder, mod dot r s holds the service, which

00:00:18.535 --> 00:00:20.463
is the code other parts of the app call.

00:00:21.361 --> 00:00:24.408
The memory folder declares the data that the feature saves.

00:00:25.306 --> 00:00:27.910
That declaration has a version in its file name.

00:00:30.033 --> 00:00:33.171
A client calls put with player nine and score forty-two.

00:00:34.071 --> 00:00:37.105
The update attribute makes this function a public method.

00:00:38.003 --> 00:00:40.217
Its guard lets only a controller call it.

00:00:41.115 --> 00:00:44.240
The body asks the root for write access and calls the scores

00:00:44.253 --> 00:00:44.839
service.

00:00:45.738 --> 00:00:48.785
The service method opens its own saved data for writing and

00:00:48.798 --> 00:00:50.516
inserts the score into a map.

00:00:51.415 --> 00:00:54.397
The field is visible only inside the scores module.

00:00:55.295 --> 00:00:58.589
An endpoint cannot reach it, and neither can another feature.

00:00:59.488 --> 00:01:00.373
They call put.

00:01:02.533 --> 00:01:05.032
Reading works the same way with one difference.

00:01:05.933 --> 00:01:07.600
A query calls root read.

00:01:08.498 --> 00:01:11.545
The service method copies the value out and returns it.

00:01:12.443 --> 00:01:14.384
The client receives Some forty-two.

00:01:15.282 --> 00:01:17.938
Read methods are written for any kind of access.

00:01:18.837 --> 00:01:21.402
Write methods exist only under a write scope.

00:01:22.300 --> 00:01:25.282
Quickstart includes a test that tries to call put from a read

00:01:25.295 --> 00:01:27.496
scope, and it must fail to compile.

00:01:29.633 --> 00:01:32.406
The same service runs in an ordinary Rust test.

00:01:33.306 --> 00:01:37.030
The test installs the app, saves two scores in one write scope,

00:01:37.174 --> 00:01:38.788
and reads the first one back.

00:01:39.687 --> 00:01:41.184
Then the test drops the app.

00:01:42.083 --> 00:01:45.351
The service objects are gone, and the saved scores are still

00:01:45.364 --> 00:01:45.650
there.

00:01:46.549 --> 00:01:49.869
Opening the app again builds new services over the same data.

00:01:50.767 --> 00:01:51.770
The count is two.

00:01:52.668 --> 00:01:56.327
Removing player nine works once, and player seventeen still

00:01:56.340 --> 00:01:57.239
has thirteen.

00:01:58.137 --> 00:02:00.846
Every stateful feature in an app follows this shape.

00:02:01.744 --> 00:02:05.429
Next we add one to a larger app, starting from an empty folder.

