]> git.lizzy.rs Git - rust.git/commitdiff
Add a core::heap::Void extern type.
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 2 Apr 2018 09:26:16 +0000 (11:26 +0200)
committerSimon Sapin <simon.sapin@exyr.org>
Thu, 12 Apr 2018 20:52:47 +0000 (22:52 +0200)
src/libcore/heap.rs
src/libcore/lib.rs

index fe19c923a58d153d2add0d72ed39c72b1e7e6929..80eedb5bff22aa1c6ba4c906775e4f425374bb5d 100644 (file)
 use usize;
 use ptr::{self, NonNull};
 
+extern {
+    /// An opaque, unsized type. Used for pointers to allocated memory.
+    ///
+    /// This type can only be used behind a pointer like `*mut Void` or `ptr::NonNull<Void>`.
+    /// Such pointers are similar to C’s `void*` type.
+    pub type Void;
+}
+
+impl Void {
+    /// Similar to `std::ptr::null`, which requires `T: Sized`.
+    pub fn null() -> *const Self {
+        0 as _
+    }
+
+    /// Similar to `std::ptr::null_mut`, which requires `T: Sized`.
+    pub fn null_mut() -> *mut Self {
+        0 as _
+    }
+}
+
 /// Represents the combination of a starting address and
 /// a total capacity of the returned block.
 #[derive(Debug)]
index 9ff8465bc0f2d87037f00a2c02107266b18c3267..722a9de215c45fc8f5eed197c00ff19f1df3e365 100644 (file)
@@ -75,6 +75,7 @@
 #![feature(custom_attribute)]
 #![feature(doc_cfg)]
 #![feature(doc_spotlight)]
+#![feature(extern_types)]
 #![feature(fn_must_use)]
 #![feature(fundamental)]
 #![feature(intrinsics)]