//! returns: 0 //! Test basic opaque pointer usage (automatic coercion). fn testOpaqueCasting() -> bool { let x: u32 = 42; let ptr: *u8 = &x as *u8; let opq: *opaque = ptr; // Automatic coercion from *u8 to *opaque. let back: *u8 = opq as *u8; return back == ptr; } /// Test that opaque can be used in function parameters. fn takesOpaque(ptr: *opaque, orig: *u8) -> bool { let back: *u8 = ptr as *u8; return back == orig; } fn testOpaqueParams() -> bool { let x: u32 = 42; let ptr: *u8 = &x as *u8; return takesOpaque(ptr, ptr); // Automatic coercion in function call. } /// Test that opaque can be used in return types. fn returnsOpaque(ptr: *u8) -> *opaque { return ptr; // Automatic coercion in return. } fn testOpaqueReturn() -> bool { let x: u32 = 42; let ptr: *u8 = &x as *u8; let opq: *opaque = returnsOpaque(ptr); return opq as *u8 == ptr; } /// Test nullable opaque pointers. fn testNullableOpaque() -> bool { let mut opt: ?*opaque = nil; if opt == nil { let x: u32 = 42; let ptr: *u8 = &x as *u8; opt = ptr; // Automatic coercion in assignment. if let p = opt { return p as *u8 == ptr; } } return false; } @default fn main() -> u32 { assert testOpaqueCasting(); assert testOpaqueParams(); assert testOpaqueReturn(); assert testNullableOpaque(); return 0; }