rustubs/
black_magic.rs

1//! collection of hacks
2use core::slice;
3
4pub unsafe fn make_static(r: &[u8]) -> &'static [u8] {
5	return slice::from_raw_parts(&r[0] as *const u8, r.len());
6}
7
8// an empty struct
9pub struct Void;
10impl Void {
11	pub const fn new() -> Self { Self {} }
12}
13
14/// flush a volatile variable: rust doesn't have a volatile keyword. When a
15/// "const static" variable is expected to be written externally the optimized
16/// code may go wrong.
17pub fn flush<T>(thing: &T) -> T {
18	unsafe { core::ptr::read_volatile(thing as *const T) }
19}