Skip to content

Commit 9b06886

Browse files
committed
Add a core::heap::Void extern type.
1 parent 1569f8f commit 9b06886

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/libcore/heap.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ use mem;
2121
use usize;
2222
use ptr::{self, NonNull};
2323

24+
extern {
25+
/// An opaque, unsized type. Used for pointers to allocated memory.
26+
///
27+
/// This type can only be used behind a pointer like `*mut Void` or `ptr::NonNull<Void>`.
28+
/// Such pointers are similar to C’s `void*` type.
29+
pub type Void;
30+
}
31+
32+
impl Void {
33+
/// Similar to `std::ptr::null`, which requires `T: Sized`.
34+
pub fn null() -> *const Self {
35+
0 as _
36+
}
37+
38+
/// Similar to `std::ptr::null_mut`, which requires `T: Sized`.
39+
pub fn null_mut() -> *mut Self {
40+
0 as _
41+
}
42+
}
43+
2444
/// Represents the combination of a starting address and
2545
/// a total capacity of the returned block.
2646
#[derive(Debug)]

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#![feature(custom_attribute)]
7676
#![feature(doc_cfg)]
7777
#![feature(doc_spotlight)]
78+
#![feature(extern_types)]
7879
#![feature(fn_must_use)]
7980
#![feature(fundamental)]
8081
#![feature(intrinsics)]

0 commit comments

Comments
 (0)