| 1 |
//! Reference-section example for `link-section`. |
| 2 |
#![warn(missing_docs)] |
| 3 |
|
| 4 |
use link_section::section; |
| 5 |
|
| 6 |
/// Operations. |
| 7 |
#[section(mutable)] |
| 8 |
pub static OPERATIONS: link_section::TypedMutableSection<&'static str>; |
| 9 |
|
| 10 |
mod operations { |
| 11 |
use link_section::in_section; |
| 12 |
|
| 13 |
#[in_section(super::OPERATIONS)] |
| 14 |
const OPERATION_1: &'static str = "operation_1"; |
| 15 |
|
| 16 |
#[in_section(super::OPERATIONS)] |
| 17 |
const OPERATION_2: &'static str = "operation_2"; |
| 18 |
|
| 19 |
#[in_section(super::OPERATIONS)] |
| 20 |
const OPERATION_3: &'static str = "operation_3"; |
| 21 |
} |
| 22 |
|
| 23 |
#[allow(unsafe_code)] |
| 24 |
fn main() { |
| 25 |
// This should normally be done in a `ctor`, but for this example we know |
| 26 |
// there are no other live threads and we do it here. |
| 27 |
{ |
| 28 |
let ops = unsafe { OPERATIONS.as_mut_slice() }; |
| 29 |
ops.sort_unstable(); |
| 30 |
} |
| 31 |
|
| 32 |
for op in OPERATIONS { |
| 33 |
println!("Operation: {}", op); |
| 34 |
} |
| 35 |
} |