From e51146a98cc7c83ea574d13b4b5d8e7ceeeb004b Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 23 Apr 2023 13:22:35 +0200 Subject: Move tips into their own subdir --- book/en/src/by-example/tips/static_lifetimes.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 book/en/src/by-example/tips/static_lifetimes.md (limited to 'book/en/src/by-example/tips/static_lifetimes.md') diff --git a/book/en/src/by-example/tips/static_lifetimes.md b/book/en/src/by-example/tips/static_lifetimes.md new file mode 100644 index 0000000..b1fd606 --- /dev/null +++ b/book/en/src/by-example/tips/static_lifetimes.md @@ -0,0 +1,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 +{{#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}} +``` -- cgit v1.2.3 From a66540efa014b3716d252612bfc7f8f17ed765c4 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sun, 23 Apr 2023 15:33:56 +0200 Subject: Disable the playground on all of these --- book/en/src/by-example/tips/static_lifetimes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'book/en/src/by-example/tips/static_lifetimes.md') diff --git a/book/en/src/by-example/tips/static_lifetimes.md b/book/en/src/by-example/tips/static_lifetimes.md index b1fd606..f4e4829 100644 --- a/book/en/src/by-example/tips/static_lifetimes.md +++ b/book/en/src/by-example/tips/static_lifetimes.md @@ -8,7 +8,7 @@ In the following example two different tasks share a [`heapless::spsc::Queue`] f [`heapless::spsc::Queue`]: https://docs.rs/heapless/0.7.5/heapless/spsc/struct.Queue.html -``` rust +``` rust,noplayground {{#include ../../../../../rtic/examples/static.rs}} ``` -- cgit v1.2.3