Skip to content

Commit 025d78a

Browse files
More docs
1 parent 5a3a64e commit 025d78a

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

rubicon/src/lib.rs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ compile_error!("The features `export-globals` and `import-globals` cannot be use
44
#[cfg(any(feature = "export-globals", feature = "import-globals"))]
55
pub use paste::paste;
66

7-
//===== crimes
7+
//==============================================================================
8+
// Wrappers
9+
//==============================================================================
810

9-
/// This gets rid of Rust compiler errors when trying to refer to an `extern`
10-
/// static. That error is there for a reason, but we're doing crimes.
11+
/// Wrapper around an `extern` `static` ref to avoid requiring `unsafe` for imported globals.
1112
pub struct TrustedExtern<T: 'static>(pub &'static T);
1213

1314
use std::ops::Deref;
@@ -19,17 +20,26 @@ impl<T> Deref for TrustedExtern<T> {
1920
}
2021
}
2122

23+
/// Wrapper around an `extern` `static` double-ref to avoid requiring `unsafe` for imported globals.
24+
///
25+
/// The reason we have a double-ref is that when exporting thread-locals, the dynamic symbol is
26+
/// already a ref. Then, in our own static, we can only access the address of that ref, not its
27+
/// value (since its value is only known as load time, not compile time).
28+
///
29+
/// As a result, imported thread-locals have an additional layer of indirection.
2230
pub struct TrustedExternDouble<T: 'static>(pub &'static &'static T);
2331

2432
impl<T> Deref for TrustedExternDouble<T> {
2533
type Target = T;
2634
fn deref(&self) -> &Self::Target {
27-
// autoderef plays a role here
35+
// autoderef goes brrr
2836
self.0
2937
}
3038
}
3139

32-
//===== thread-locals
40+
//==============================================================================
41+
// Thread-locals
42+
//==============================================================================
3343

3444
#[cfg(not(any(feature = "import-globals", feature = "export-globals")))]
3545
#[macro_export]
@@ -99,7 +109,9 @@ macro_rules! thread_local_inner {
99109
};
100110
}
101111

102-
//===== process-locals (statics)
112+
//==============================================================================
113+
// Process-locals (statics)
114+
//==============================================================================
103115

104116
#[cfg(all(not(feature = "import-globals"), not(feature = "export-globals")))]
105117
#[macro_export]
@@ -196,31 +208,37 @@ macro_rules! process_local_inner_mut {
196208
};
197209
}
198210

199-
//===== soprintln!
211+
//==============================================================================
212+
// soprintln
213+
//==============================================================================
200214

201-
#[no_mangle]
215+
/// Note: there's one copy of this static per shared object on purpose — that's the one
216+
/// static we DON'T want to deduplicate.
217+
#[used]
202218
static SHARED_OBJECT_ID_REF: u64 = 0;
203219

204220
/// Returns a unique identifier for the current shared object
205-
/// (based on the address of the `shared_object_id_ref` function).
221+
/// (based on the address of the `SHARED_OBJECT_ID_REF` static).
206222
pub fn shared_object_id() -> u64 {
207223
&SHARED_OBJECT_ID_REF as *const _ as u64
208224
}
209225

226+
/// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
210227
#[cfg(feature = "import-globals")]
211228
pub static RUBICON_MODE: &str = "I"; // "import"
212229

230+
/// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
213231
#[cfg(feature = "export-globals")]
214232
pub static RUBICON_MODE: &str = "E"; // "export"
215233

234+
/// Defined to `I` when importing globals, `E` when exporting globals, and `N` otherwise.
216235
#[cfg(not(any(feature = "import-globals", feature = "export-globals")))]
217236
pub static RUBICON_MODE: &str = "N"; // "normal"
218237

219238
#[cfg(all(feature = "import-globals", feature = "export-globals"))]
220239
compile_error!("The features \"import-globals\" and \"export-globals\" are mutually exclusive");
221240

222-
/// A u64 value, with an automatically-generated foreground and background color,
223-
/// with a `Display` implementation that prints the value with 24-bit color ANSI escape codes.
241+
/// A `u64` whose 24-bit ANSI color is determined by its value.
224242
pub struct Beacon<'a> {
225243
fg: (u8, u8, u8),
226244
bg: (u8, u8, u8),
@@ -345,6 +363,12 @@ macro_rules! soprintln {
345363
};
346364
}
347365

366+
/// `soprintln!` prints a message prefixed by a truncated timestamp, shared object ID and thread ID.
367+
///
368+
/// It is costly, which is why it's behind a cargo feature AND an environment variable.
369+
///
370+
/// To see soprintln output, enable the `soprintln` cargo feature, and set the `SO_PRINTLN`
371+
/// environment variable to `1`.
348372
#[macro_export]
349373
#[cfg(not(feature = "soprintln"))]
350374
macro_rules! soprintln {

0 commit comments

Comments
 (0)