1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::cell::UnsafeCell;
use crate::inventory;
use crate::StringRef;
#[macro_export]
macro_rules! byond_string {
($s:literal) => {
unsafe {
static mut STORE: $crate::InternedString =
$crate::InternedString($s, std::cell::UnsafeCell::new(None));
$crate::inventory::submit!(unsafe { &STORE });
let x = &*STORE.1.get();
x.as_ref().unwrap()
}
};
}
unsafe impl Sync for InternedString {}
#[doc(hidden)]
pub struct InternedString(pub &'static str, pub UnsafeCell<Option<StringRef>>);
inventory::collect!(&'static InternedString);
pub fn setup_interned_strings() {
for info in inventory::iter::<&'static InternedString> {
let string = StringRef::new(info.0).expect("failed to create interned string");
unsafe {
let dst = &mut *info.1.get();
*dst = Some(string);
}
}
}
pub fn destroy_interned_strings() {
for info in inventory::iter::<&'static InternedString> {
unsafe {
let dst = &mut *info.1.get();
*dst = None;
}
}
}