Extern type

From Rust Community Wiki
Jump to navigation Jump to search

Note: This is a nightly-only feature.

An extern type is a type which the compiler knows nothing about. It might be dynamically sized or have a fixed size, but either way the compiler doesn't know the size. The main purpose of extern types is interoperability with other languages, e.g. C; it is equivalent to a void pointer (void *) in C.

Like DSTs, extern types must be behind a reference or a pointer-like type, such as BoxThis links to official Rust documentation. Unlike a DST, a reference/pointer to an extern type is a regular (thin) pointer, not a fat pointer.

Example[edit | edit source]


extern {
    type Foo;

extern "C" fn foo(_: *const Foo) {}