Skip to content

Commit d55cdd1

Browse files
Mhjh
1 parent 025d78a commit d55cdd1

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

rubicon/src/lib.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub use paste::paste;
99
//==============================================================================
1010

1111
/// Wrapper around an `extern` `static` ref to avoid requiring `unsafe` for imported globals.
12+
#[doc(hidden)]
1213
pub struct TrustedExtern<T: 'static>(pub &'static T);
1314

1415
use std::ops::Deref;
@@ -27,6 +28,7 @@ impl<T> Deref for TrustedExtern<T> {
2728
/// value (since its value is only known as load time, not compile time).
2829
///
2930
/// As a result, imported thread-locals have an additional layer of indirection.
31+
#[doc(hidden)]
3032
pub struct TrustedExternDouble<T: 'static>(pub &'static &'static T);
3133

3234
impl<T> Deref for TrustedExternDouble<T> {
@@ -41,6 +43,22 @@ impl<T> Deref for TrustedExternDouble<T> {
4143
// Thread-locals
4244
//==============================================================================
4345

46+
/// Imports or exports a thread-local, depending on the enabled cargo features.
47+
///
48+
/// Usage:
49+
///
50+
/// ```ignore
51+
/// use rubicon::process_local;
52+
///
53+
/// process_local! {
54+
/// static FOO: u32 = 42;
55+
/// }
56+
/// ```
57+
///
58+
/// This will import `FOO` if the `import-globals` feature is enabled, and export it if the
59+
/// `export-globals` feature is enabled.
60+
///
61+
/// If neither feature is enabled, this will expand to the static declaration itself.
4462
#[cfg(not(any(feature = "import-globals", feature = "export-globals")))]
4563
#[macro_export]
4664
macro_rules! thread_local {
@@ -113,6 +131,23 @@ macro_rules! thread_local_inner {
113131
// Process-locals (statics)
114132
//==============================================================================
115133

134+
/// Imports or exports a `static`, depending on the enabled cargo features.
135+
///
136+
/// Usage:
137+
///
138+
/// ```ignore
139+
/// rubicon::process_local! {
140+
/// static FOO: u32 = 42;
141+
/// }
142+
/// ```
143+
///
144+
/// This will import `FOO` if the `import-globals` feature is enabled, and export it if the
145+
/// `export-globals` feature is enabled.
146+
///
147+
/// If neither feature is enabled, this will expand to the static declaration itself.
148+
///
149+
/// This macro supports multiple declarations, along with `static mut` declarations
150+
/// (which have a slightly different expansion).
116151
#[cfg(all(not(feature = "import-globals"), not(feature = "export-globals")))]
117152
#[macro_export]
118153
macro_rules! process_local {
@@ -217,8 +252,7 @@ macro_rules! process_local_inner_mut {
217252
#[used]
218253
static SHARED_OBJECT_ID_REF: u64 = 0;
219254

220-
/// Returns a unique identifier for the current shared object
221-
/// (based on the address of the `SHARED_OBJECT_ID_REF` static).
255+
/// Returns a unique identifier for the current shared object.
222256
pub fn shared_object_id() -> u64 {
223257
&SHARED_OBJECT_ID_REF as *const _ as u64
224258
}
@@ -239,6 +273,8 @@ pub static RUBICON_MODE: &str = "N"; // "normal"
239273
compile_error!("The features \"import-globals\" and \"export-globals\" are mutually exclusive");
240274

241275
/// A `u64` whose 24-bit ANSI color is determined by its value.
276+
///
277+
/// Used by the [`soprintln`] macro to visually distinguish shared objects and threads.
242278
pub struct Beacon<'a> {
243279
fg: (u8, u8, u8),
244280
bg: (u8, u8, u8),

0 commit comments

Comments
 (0)