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
#![cfg_attr(feature = "nightly", feature(structural_match))]
#![cfg_attr(not(test), no_std)]
mod ptr32;
mod ptr64;
pub use self::ptr32::*;
pub use self::ptr64::*;
#[cfg(target_pointer_width = "32")]
#[doc(no_inline)]
pub use IntPtr32 as IntPtr;
#[cfg(target_pointer_width = "64")]
#[doc(no_inline)]
pub use IntPtr64 as IntPtr;
impl<T: ?Sized> From<IntPtr32<T>> for IntPtr64<T> {
#[inline]
fn from(ptr: IntPtr32<T>) -> IntPtr64<T> {
IntPtr64::from(ptr.into_raw() as u64)
}
}
#[cfg(feature = "nightly")]
#[test]
fn test_match() {
const TEST_PTR: IntPtr = IntPtr::from_raw(0x1000);
match TEST_PTR {
TEST_PTR => (),
_ => panic!(),
}
}
#[test]
fn raw_ptr() {
fn c_api(_: *const ()) {}
fn c_mut(_: *mut ()) {}
let ptr = IntPtr::<i32>::from_usize(0x1000);
c_api(ptr.cast().as_ptr());
c_mut(ptr.cast().as_mut_ptr());
}