rustubs/
black_magic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! collection of hacks
use core::slice;

pub unsafe fn make_static(r: &[u8]) -> &'static [u8] {
	return slice::from_raw_parts(&r[0] as *const u8, r.len());
}

// an empty struct
pub struct Void;
impl Void {
	pub const fn new() -> Self { Self {} }
}

/// flush a volatile variable: rust doesn't have a volatile keyword. When a
/// "const static" variable is expected to be written externally the optimized
/// code may go wrong.
pub fn flush<T>(thing: &T) -> T {
	unsafe { core::ptr::read_volatile(thing as *const T) }
}