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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
pub const fn empty_slice<'a, T>() -> &'a [T]
where
T: 'a,
{
GetEmptySlice::<'a, T>::EMPTY
}
struct GetEmptySlice<'a, T>(&'a T);
impl<'a, T> GetEmptySlice<'a, T>
where
T: 'a,
{
const EMPTY: &'a [T] = &[];
}
#[inline(never)]
#[cold]
pub fn ffi_panic_message(file: &'static str, line: u32) -> ! {
eprintln!("\nfile:{}\nline:{}", file, line);
eprintln!("Attempted to panic across the ffi boundary.");
eprintln!("Aborting to handle the panic...\n");
::std::process::abort();
}
#[inline]
pub fn leak_value<'a,T>(value:T)->&'a T
where T:'a
{
let x=Box::new(value);
Box::leak(x)
}
pub unsafe fn transmute_reference<T,U>(ref_:&T)->&U{
&*(ref_ as *const _ as *const U)
}
pub unsafe fn transmute_mut_reference<T,U>(ref_:&mut T)->&mut U{
&mut *(ref_ as *mut _ as *mut U)
}