aboutsummaryrefslogtreecommitdiff
path: root/book/en/src/by-example/resources.md
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2020-10-05 18:25:15 +0200
committerEmil Fresk <emil.fresk@gmail.com>2020-10-05 18:25:15 +0200
commiteec0908024d9b4127ed496b4781adc08000cc2c2 (patch)
treef128b3d91ea4ac0f171ab334d4517552a6803d01 /book/en/src/by-example/resources.md
parent9d2598dc071882a94b813ab1d9ddf49092546257 (diff)
parentf493f21359ccb3ab4643d9470f3581532f47593a (diff)
Merge branch 'master' into always_late_resources
Diffstat (limited to 'book/en/src/by-example/resources.md')
-rw-r--r--book/en/src/by-example/resources.md18
1 files changed, 12 insertions, 6 deletions
diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md
index b9e92d1..d082dfc 100644
--- a/book/en/src/by-example/resources.md
+++ b/book/en/src/by-example/resources.md
@@ -4,11 +4,13 @@ The framework provides an abstraction to share data between any of the contexts
we saw in the previous section (task handlers, `init` and `idle`): resources.
Resources are data visible only to functions declared within the `#[app]`
-pseudo-module. The framework gives the user complete control over which context
+module. The framework gives the user complete control over which context
can access which resource.
All resources are declared as a single `struct` within the `#[app]`
-pseudo-module. Each field in the structure corresponds to a different resource.
+module. Each field in the structure corresponds to a different resource.
+The `struct` must be annotated with the following attribute: `#[resources]`.
+
Resources can optionally be given an initial value using the `#[init]`
attribute. Resources that are not given an initial value are referred to as
*late* resources and are covered in more detail in a follow-up section in this
@@ -29,7 +31,8 @@ access to a resource named `shared`.
``` console
$ cargo run --example resource
-{{#include ../../../../ci/expected/resource.run}}```
+{{#include ../../../../ci/expected/resource.run}}
+```
Note that the `shared` resource cannot be accessed from `idle`. Attempting to do
so results in a compile error.
@@ -71,7 +74,8 @@ lowest priority handler.
``` console
$ cargo run --example lock
-{{#include ../../../../ci/expected/lock.run}}```
+{{#include ../../../../ci/expected/lock.run}}
+```
## Late resources
@@ -97,7 +101,8 @@ the consumer resource.
``` console
$ cargo run --example late
-{{#include ../../../../ci/expected/late.run}}```
+{{#include ../../../../ci/expected/late.run}}
+```
## Only shared access
@@ -127,4 +132,5 @@ any kind of lock.
``` console
$ cargo run --example only-shared-access
-{{#include ../../../../ci/expected/only-shared-access.run}}```
+{{#include ../../../../ci/expected/only-shared-access.run}}
+```