| 1 |
use link_section::declarative::{in_section, section}; |
| 2 |
use link_section::TypedReferenceSection; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#[allow(non_camel_case_types)] |
| 7 |
struct FOO; |
| 8 |
impl FOO { |
| 9 |
/// Get a `const` reference to the underlying section. In |
| 10 |
/// non-const contexts, `deref` is sufficient. |
| 11 |
pub const fn const_deref(&self) -> &'static TypedReferenceSection<u32> { |
| 12 |
static SECTION: TypedReferenceSection<u32> = |
| 13 |
{ |
| 14 |
let section = |
| 15 |
{ |
| 16 |
static __LINK_SECTION_NAME: &'static str = |
| 17 |
".data.link_section.FOO"; |
| 18 |
#[export_name = ".data.link_section.FOO.bounds"] |
| 19 |
#[used] |
| 20 |
#[used] |
| 21 |
static __LINK_SECTION_INFO: |
| 22 |
::link_section::__support::wasm::LinkSectionInfoLock<::link_section::__support::wasm::LinkSectionInfo> |
| 23 |
= |
| 24 |
::link_section::__support::wasm::LinkSectionInfoLock::new(::link_section::__support::wasm::LinkSectionInfo::new::<(u32)>(__LINK_SECTION_NAME, |
| 25 |
true)); |
| 26 |
#[link_section = ".init_array.1"] |
| 27 |
#[used] |
| 28 |
#[allow(non_snake_case)] |
| 29 |
static __LINK_SECTION_FLATTEN_FN_REF: extern "C" fn() = |
| 30 |
{ |
| 31 |
extern "C" fn __LINK_SECTION_FLATTEN_FN() { |
| 32 |
unsafe { |
| 33 |
::link_section::__support::wasm::flatten(&raw const __LINK_SECTION_INFO); |
| 34 |
} |
| 35 |
} |
| 36 |
__LINK_SECTION_FLATTEN_FN |
| 37 |
}; |
| 38 |
unsafe { |
| 39 |
<::link_section::__support::Bounds>::new(&raw const __LINK_SECTION_INFO) |
| 40 |
} |
| 41 |
}; |
| 42 |
let name = ".data.link_section.FOO"; |
| 43 |
::link_section::__support::validate_section_name(name); |
| 44 |
unsafe { <TypedReferenceSection<u32>>::new(name, section) } |
| 45 |
}; |
| 46 |
&SECTION |
| 47 |
} |
| 48 |
} |
| 49 |
impl ::core::fmt::Debug for FOO { |
| 50 |
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { |
| 51 |
::core::ops::Deref::deref(self).fmt(f) |
| 52 |
} |
| 53 |
} |
| 54 |
impl ::core::ops::Deref for FOO { |
| 55 |
type Target = TypedReferenceSection<u32>; |
| 56 |
fn deref(&self) -> &Self::Target { self.const_deref() } |
| 57 |
} |
| 58 |
impl ::link_section::__support::SectionItemType for FOO { |
| 59 |
type Item = (u32); |
| 60 |
} |
| 61 |
impl ::link_section::__support::SectionItemTyped<(u32)> for FOO { |
| 62 |
type Item = (u32); |
| 63 |
} |
| 64 |
impl FOO { |
| 65 |
/// Get the section as a slice. |
| 66 |
pub fn as_slice(&self) -> &[(u32)] { self.const_deref().as_slice() } |
| 67 |
} |
| 68 |
impl ::core::iter::IntoIterator for FOO { |
| 69 |
type Item = &'static (u32); |
| 70 |
type IntoIter = ::core::slice::Iter<'static, (u32)>; |
| 71 |
fn into_iter(self) -> Self::IntoIter { |
| 72 |
self.const_deref().as_slice().iter() |
| 73 |
} |
| 74 |
} |
| 75 |
const ITEM: u32 = |
| 76 |
const { |
| 77 |
type __InSecStoredTy = |
| 78 |
<::link_section::TypedSection<u32> as |
| 79 |
::link_section::__support::SectionItemType>::Item; |
| 80 |
const __LINK_SECTION_CONST_ITEM_VALUE: __InSecStoredTy = 42; |
| 81 |
#[used] |
| 82 |
static __LINK_SECTION_CELL: |
| 83 |
::link_section::__support::wasm::LinkCell<__InSecStoredTy, |
| 84 |
::link_section::__support::wasm::LinkMetaSlot> = |
| 85 |
<::link_section::__support::wasm::LinkCell<__InSecStoredTy, |
| 86 |
::link_section::__support::wasm::LinkMetaSlot>>::new(__LINK_SECTION_CONST_ITEM_VALUE, |
| 87 |
::core::ptr::null()); |
| 88 |
#[allow(missing_unsafe_on_extern)] |
| 89 |
extern "C" { |
| 90 |
#[link_name = ".data.link_section.FOO.bounds"] |
| 91 |
static __LINK_SECTION_INFO: |
| 92 |
::link_section::__support::wasm::LinkSectionInfoLock<::link_section::__support::wasm::LinkSectionInfo>; |
| 93 |
} |
| 94 |
#[link_section = ".init_array.0"] |
| 95 |
#[used] |
| 96 |
#[allow(non_snake_case)] |
| 97 |
static __LINK_SECTION_ITEM_FN_REF: extern "C" fn() = |
| 98 |
{ |
| 99 |
extern "C" fn __LINK_SECTION_ITEM_FN() { |
| 100 |
unsafe { |
| 101 |
::link_section::__support::wasm::register(&raw const __LINK_SECTION_INFO, |
| 102 |
__LINK_SECTION_CELL.as_cell_ptr()); |
| 103 |
} |
| 104 |
} |
| 105 |
__LINK_SECTION_ITEM_FN |
| 106 |
}; |
| 107 |
__LINK_SECTION_CONST_ITEM_VALUE |
| 108 |
}; |
| 109 |
fn main() {} |