diff options
| author | Jorge Aparicio <jorge@japaric.io> | 2019-02-11 21:40:53 +0100 |
|---|---|---|
| committer | Jorge Aparicio <jorge@japaric.io> | 2019-02-11 21:40:53 +0100 |
| commit | 0007a35a274ab2d07eb937e41971ea5e2c1cb5ff (patch) | |
| tree | 98361d6d3dfced4b068771c31163b324573294b7 /book/en/src/by-example/singletons.md | |
| parent | 68a937a72a3a6d261076803d38b7d9b2cb9e3067 (diff) | |
change layout of books
Diffstat (limited to 'book/en/src/by-example/singletons.md')
| -rw-r--r-- | book/en/src/by-example/singletons.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/book/en/src/by-example/singletons.md b/book/en/src/by-example/singletons.md new file mode 100644 index 0000000..0823f05 --- /dev/null +++ b/book/en/src/by-example/singletons.md @@ -0,0 +1,26 @@ +# Singletons + +The `app` attribute is aware of [`owned-singleton`] crate and its [`Singleton`] +attribute. When this attribute is applied to one of the resources the runtime +will perform the `unsafe` initialization of the singleton for you, ensuring that +only a single instance of the singleton is ever created. + +[`owned-singleton`]: ../../api/owned_singleton/index.html +[`Singleton`]: ../../api/owned_singleton_macros/attr.Singleton.html + +Note that when using the `Singleton` attribute you'll need to have the +`owned_singleton` in your dependencies. + +Below is an example that uses the `Singleton` attribute on a chunk of memory +and then uses the singleton instance as a fixed-size memory pool using one of +the [`alloc-singleton`] abstractions. + +[`alloc-singleton`]: https://crates.io/crates/alloc-singleton + +``` rust +{{#include ../../../../examples/singleton.rs}} +``` + +``` console +$ cargo run --example singleton +{{#include ../../../../ci/expected/singleton.run}}``` |
