aboutsummaryrefslogtreecommitdiff
path: root/book/en/src/by-example/tips/static_lifetimes.md
blob: f4e4829f7eb6c4f0cd7743ee5823d0e27ab3eec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 'static super-powers

In `#[init]` and `#[idle]` `local` resources have `'static` lifetime.

Useful when pre-allocating and/or splitting resources between tasks, drivers or some other object. This comes in handy when drivers, such as USB drivers, need to allocate memory and when using splittable data structures such as [`heapless::spsc::Queue`].

In the following example two different tasks share a [`heapless::spsc::Queue`] for lock-free access to the shared queue.

[`heapless::spsc::Queue`]: https://docs.rs/heapless/0.7.5/heapless/spsc/struct.Queue.html

``` rust,noplayground
{{#include ../../../../../rtic/examples/static.rs}}
```

Running this program produces the expected output.

``` console
$ cargo run --target thumbv7m-none-eabi --example static
```

``` console
{{#include ../../../../../rtic/ci/expected/static.run}}
```