| 1 |
//! Reference-section example for `link-section`. |
| 2 |
#![warn(missing_docs)] |
| 3 |
|
| 4 |
mod operations { |
| 5 |
use link_section::{in_section, section}; |
| 6 |
|
| 7 |
/// Operations. |
| 8 |
#[section(typed)] |
| 9 |
pub static OPERATIONS: link_section::TypedSection<&'static str>; |
| 10 |
|
| 11 |
#[in_section(OPERATIONS)] |
| 12 |
static OPERATION_1: &'static str = "operation_1"; |
| 13 |
|
| 14 |
#[in_section(OPERATIONS)] |
| 15 |
static OPERATION_2: &'static str = "operation_2"; |
| 16 |
|
| 17 |
#[in_section(OPERATIONS)] |
| 18 |
static OPERATION_3: &'static str = "operation_3"; |
| 19 |
} |
| 20 |
|
| 21 |
mod referenced_operations { |
| 22 |
use link_section::{in_section, section}; |
| 23 |
|
| 24 |
#[section(reference)] |
| 25 |
pub static OPERATIONS: link_section::TypedReferenceSection<&'static str>; |
| 26 |
|
| 27 |
#[in_section(OPERATIONS)] |
| 28 |
pub static REF_OPERATION_1: &'static str = "ref_operation_1"; |
| 29 |
} |
| 30 |
|
| 31 |
fn main() { |
| 32 |
for op in operations::OPERATIONS { |
| 33 |
println!("Operation: {}", op); |
| 34 |
} |
| 35 |
for op in referenced_operations::OPERATIONS { |
| 36 |
println!("Referenced Operation: {}", op); |
| 37 |
} |
| 38 |
println!("OPERATIONS: {:?}", operations::OPERATIONS); |
| 39 |
println!("REF_OPERATIONS: {:?}", referenced_operations::OPERATIONS); |
| 40 |
println!( |
| 41 |
"REF_OPERATION_1: {}", |
| 42 |
*referenced_operations::REF_OPERATION_1 |
| 43 |
); |
| 44 |
} |