aboutsummaryrefslogtreecommitdiff
path: root/src/macros.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-01-15 17:04:45 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-01-15 17:04:45 +0100
commit4f9664c54c4dbe5c05cb7a1afa29f2f6952e1ada (patch)
treecac8651f3c9ac187c83496bae5bd1493c668d84e /src/macros.rs
parent74045f24f8bd2dcee6c1dcde0f9db63de192d7e5 (diff)
downloadcortex-m-4f9664c54c4dbe5c05cb7a1afa29f2f6952e1ada.tar.gz
cortex-m-4f9664c54c4dbe5c05cb7a1afa29f2f6952e1ada.tar.zst
cortex-m-4f9664c54c4dbe5c05cb7a1afa29f2f6952e1ada.zip
address review comments
Diffstat (limited to 'src/macros.rs')
-rw-r--r--src/macros.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/macros.rs b/src/macros.rs
index bd43b4f..c9a32c2 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -23,7 +23,7 @@ macro_rules! iprintln {
};
}
-/// Macro to create an statically allocated value
+/// Macro to create a mutable reference to a statically allocated value
///
/// This macro returns a value with type `Option<&'static mut $ty>`. `Some($expr)` will be returned
/// the first time the macro is executed; further calls will return `None`. To avoid `unwrap`ping a
@@ -32,10 +32,13 @@ macro_rules! iprintln {
///
/// # Example
///
-/// ``` ignore
+/// ``` no_run
+/// #[macro_use(singleton)]
+/// extern crate cortex_m;
+///
/// fn main() {
/// // OK if `main` is executed only once
-/// let x: &'static mut bool = static_!(: bool = false).unwrap();
+/// let x: &'static mut bool = singleton!(: bool = false).unwrap();
///
/// let y = alias();
/// // BAD this second call to `alias` will definitively `panic!`
@@ -43,11 +46,11 @@ macro_rules! iprintln {
/// }
///
/// fn alias() -> &'static mut bool {
-/// static_!(: bool = false).unwrap()
+/// singleton!(: bool = false).unwrap()
/// }
/// ```
#[macro_export]
-macro_rules! static_ {
+macro_rules! singleton {
(: $ty:ty = $expr:expr) => {
$crate::interrupt::free(|_| unsafe {
static mut USED: bool = false;