]> git.proxmox.com Git - rustc.git/blame - src/libcore/ffi.rs
New upstream version 1.31.0+dfsg1
[rustc.git] / src / libcore / ffi.rs
CommitLineData
b7449926
XL
1#![stable(feature = "", since = "1.30.0")]
2
3#![allow(non_camel_case_types)]
4
5//! Utilities related to FFI bindings.
6
7use ::fmt;
8
9/// Equivalent to C's `void` type when used as a [pointer].
10///
11/// In essence, `*const c_void` is equivalent to C's `const void*`
12/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
13/// *not* the same as C's `void` return type, which is Rust's `()` type.
14///
15/// Ideally, this type would be equivalent to [`!`], but currently it may
16/// be more ideal to use `c_void` for FFI purposes.
17///
18/// [`!`]: ../../std/primitive.never.html
19/// [pointer]: ../../std/primitive.pointer.html
20// NB: For LLVM to recognize the void pointer type and by extension
21// functions like malloc(), we need to have it represented as i8* in
22// LLVM bitcode. The enum used here ensures this and prevents misuse
23// of the "raw" type by only having private variants.. We need two
24// variants, because the compiler complains about the repr attribute
25// otherwise.
26#[repr(u8)]
27#[stable(feature = "raw_os", since = "1.1.0")]
28pub enum c_void {
29 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
30 issue = "0")]
31 #[doc(hidden)] __variant1,
32 #[unstable(feature = "c_void_variant", reason = "should not have to exist",
33 issue = "0")]
34 #[doc(hidden)] __variant2,
35}
36
37#[stable(feature = "std_debug", since = "1.16.0")]
38impl fmt::Debug for c_void {
39 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 f.pad("c_void")
41 }
42}