Skip to content

Commit ec1b06b

Browse files
committed
Hide the backing storage for static_atomic_ref! better to improve safety
1 parent 1bc9d32 commit ec1b06b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[package]
22
name = "atomic_ref"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Michael Layzell <michael@thelayzells.com>"]
55

66
description = "Atomic &'a T types with support for static allocation"
77
repository = "https://github.com/mystor/atomic_ref"
8+
documentation = "https://docs.rs/atomic_ref/"
89
readme = "README.md"
910
license = "MIT"
1011
keywords = ["atomic", "reference", "static"]

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ macro_rules! static_atomic_ref {
137137
type Target = $crate::AtomicRef<'static, $T>;
138138
#[allow(unsafe_code)]
139139
fn deref<'a>(&'a self) -> &'a $crate::AtomicRef<'static, $T> {
140-
unsafe { ::std::mem::transmute(&self._ref) }
140+
static STORAGE: $crate::AtomicRef<'static, u8> = $crate::ATOMIC_U8_REF_INIT;
141+
unsafe { ::std::mem::transmute(&STORAGE) }
141142
}
142143
}
143144
static_atomic_ref!($($t)*);
@@ -147,18 +148,18 @@ macro_rules! static_atomic_ref {
147148
#[allow(non_camel_case_types)]
148149
#[allow(dead_code)]
149150
$(#[$attr])*
150-
pub struct $N { _ref: $crate::AtomicRef<'static, u8> }
151+
pub struct $N { _private: () }
151152
#[doc(hidden)]
152-
pub static $N: $N = $N { _ref: $crate::ATOMIC_U8_REF_INIT };
153+
pub static $N: $N = $N { _private: () };
153154
};
154155
(@MAKE TY, PRIV, $(#[$attr:meta])*, $N:ident) => {
155156
#[allow(missing_copy_implementations)]
156157
#[allow(non_camel_case_types)]
157158
#[allow(dead_code)]
158159
$(#[$attr])*
159-
struct $N { _ref: $crate::AtomicRef<'static, u8> }
160+
struct $N { _private: () }
160161
#[doc(hidden)]
161-
static $N: $N = $N { _ref: $crate::ATOMIC_U8_REF_INIT };
162+
static $N: $N = $N { _private: () };
162163
};
163164
() => ();
164165
}

0 commit comments

Comments
 (0)