Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ```rust in a few more places to get syntax highlighting
  • Loading branch information
Ericson2314 committed Jan 21, 2017
commit 2f7731663801a781298a2fd4adea18a54df25a43
8 changes: 8 additions & 0 deletions text/0000-extern-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ In Rust, we don't have this feature. Instead, a couple of problematic hacks are

One is, we define the type as an uninhabited type. eg.

```rust
enum MyFfiType {}
```

Another is, we define the type with a private field and no methods to construct it.

```rust
struct MyFfiType {
_priv: (),
}
```

The point of both these constructions is to prevent the user from being able to create or deal directly with instances of the type.
Neither of these types accurately reflect the reality of the situation.
Expand All @@ -47,13 +51,17 @@ Just like unions, this is an unsafe feature necessary for dealing with legacy co

Add a new kind of type declaration, an `extern type`:

```rust
extern type Foo;
Copy link
Member

@nagisa nagisa Jan 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diverges somewhat from extern fn where its a definition and not declaration. For consistency IMHO declarations should stay constrained to extern blocks, like below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, of course. They're two different things.

```

These can also be declared inside an `extern` block:

```rust
extern {
type Foo;
}
```

These types are FFI-safe. They are also DSTs, meaning that they implement `?Sized`. Being DSTs, they cannot be kept on the stack and can only be accessed through pointers.

Expand Down