[rust-dev] Zero-variant tags?
Patrick Walton
pwalton at mozilla.com
Wed Jan 18 13:04:31 PST 2012
On 1/18/12 12:54 PM, Brendan Eich wrote:
> Occasionally useful as a basis case, a kind of void variant?
>
> /be
I usually write that as
enum foo {
foo(@foo);
}
Which creates a type foo that you can't actually create instances of
(unless you use unsafe::reinterpret_cast::<foo>(0) or similar in an
unsafe block).
But maybe "enum foo { /* unconstructible */ }" is better -- I've wanted
void to be easier to define. Note that OCaml lets you say "type foo;;"
for this. This is nice for interfacing with C; SpiderMonkey bindings
have stuff like:
enum JSRuntime {
JSRuntime(@JSRuntime)
}
So that I can write *JSRuntime instead of *int or whatever in C bindings.
This is of course useful for phantom types as well.
Patrick
More information about the Rust-dev
mailing list