summary refs log tree commit diff
path: root/src/libcore/unsafe.rs
blob: 7b99727b48a4293b316556ce18f284b4d62254df (plain)
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
#[doc = "Unsafe operations"];

export reinterpret_cast, forget;

#[abi = "rust-intrinsic"]
native mod rusti {
    fn forget<T>(-x: T);
    fn reinterpret_cast<T, U>(e: T) -> U;
}

#[doc = "
Casts the value at `src` to U. The two types must have the same length.
"]
#[inline(always)]
unsafe fn reinterpret_cast<T, U>(src: T) -> U {
    rusti::reinterpret_cast(src)
}

#[doc ="
Move a thing into the void

The forget function will take ownership of the provided value but neglect
to run any required cleanup or memory-management operations on it. This
can be used for various acts of magick, particularly when using
reinterpret_cast on managed pointer types.
"]
#[inline(always)]
unsafe fn forget<T>(-thing: T) { rusti::forget(thing); }

#[cfg(test)]
mod tests {

    #[test]
    fn test_reinterpret_cast() unsafe {
        assert reinterpret_cast(1) == 1u;
    }
}