| 1 |
use link_section::declarative::{section, in_section}; |
| 2 |
use link_section::TypedSection; |
| 3 |
|
| 4 |
struct Driver { |
| 5 |
name: &'static str, |
| 6 |
f: fn(), |
| 7 |
} |
| 8 |
|
| 9 |
impl Driver { |
| 10 |
const fn new(name: &'static str, f: fn()) -> Self { Self { name, f } } |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#[allow(non_camel_case_types)] |
| 16 |
struct FOO; |
| 17 |
impl FOO { |
| 18 |
/// Get a `const` reference to the underlying section. In |
| 19 |
/// non-const contexts, `deref` is sufficient. |
| 20 |
pub const fn const_deref(&self) -> &'static TypedSection<Driver> { |
| 21 |
static SECTION: TypedSection<Driver> = |
| 22 |
{ |
| 23 |
let section = |
| 24 |
{ |
| 25 |
; |
| 26 |
::link_section::__support::PtrBounds::new({ |
| 27 |
#[allow(missing_unsafe_on_extern)] |
| 28 |
extern "C" { |
| 29 |
#[link_name = "__start__data_link_section_FOO"] |
| 30 |
static __SYMBOL: u8; |
| 31 |
} |
| 32 |
unsafe { &raw const __SYMBOL as *const () } |
| 33 |
}, |
| 34 |
{ |
| 35 |
#[allow(missing_unsafe_on_extern)] |
| 36 |
extern "C" { |
| 37 |
#[link_name = "__stop__data_link_section_FOO"] |
| 38 |
static __SYMBOL: u8; |
| 39 |
} |
| 40 |
unsafe { &raw const __SYMBOL as *const () } |
| 41 |
}) |
| 42 |
}; |
| 43 |
let name = "_data_link_section_FOO"; |
| 44 |
::link_section::__support::validate_section_name(name); |
| 45 |
unsafe { <TypedSection<Driver>>::new(name, section) } |
| 46 |
}; |
| 47 |
&SECTION |
| 48 |
} |
| 49 |
} |
| 50 |
impl ::core::fmt::Debug for FOO { |
| 51 |
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { |
| 52 |
::core::ops::Deref::deref(self).fmt(f) |
| 53 |
} |
| 54 |
} |
| 55 |
impl ::core::ops::Deref for FOO { |
| 56 |
type Target = TypedSection<Driver>; |
| 57 |
fn deref(&self) -> &Self::Target { self.const_deref() } |
| 58 |
} |
| 59 |
impl ::link_section::__support::SectionItemType for FOO { |
| 60 |
type Item = (Driver); |
| 61 |
} |
| 62 |
impl ::link_section::__support::SectionItemTyped<(Driver)> for FOO { |
| 63 |
type Item = (Driver); |
| 64 |
} |
| 65 |
impl FOO { |
| 66 |
/// Get the section as a slice. |
| 67 |
pub fn as_slice(&self) -> &[(Driver)] { self.const_deref().as_slice() } |
| 68 |
} |
| 69 |
impl ::core::iter::IntoIterator for FOO { |
| 70 |
type Item = &'static (Driver); |
| 71 |
type IntoIter = ::core::slice::Iter<'static, (Driver)>; |
| 72 |
fn into_iter(self) -> Self::IntoIter { |
| 73 |
self.const_deref().as_slice().iter() |
| 74 |
} |
| 75 |
} |
| 76 |
const DRIVER: Driver = |
| 77 |
const { |
| 78 |
type __InSecStoredTy = |
| 79 |
<::link_section::TypedSection<Driver> as |
| 80 |
::link_section::__support::SectionItemType>::Item; |
| 81 |
const __LINK_SECTION_CONST_ITEM_VALUE: __InSecStoredTy = |
| 82 |
Driver::new("driver", || ()); |
| 83 |
#[used] |
| 84 |
#[export_name = |
| 85 |
"__LINK_SECTION_CONST_ITEM_Pexpand_probe_Mexpand_probe_L22_C1"] |
| 86 |
#[link_section = "_data_link_section_FOO"] |
| 87 |
static __LINK_SECTION_CONST_ITEM: __InSecStoredTy = |
| 88 |
__LINK_SECTION_CONST_ITEM_VALUE; |
| 89 |
__LINK_SECTION_CONST_ITEM_VALUE |
| 90 |
}; |
| 91 |
fn main() {} |