Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Unsafe enums #724
Conversation
retep998
added some commits
Jan 23, 2015
retep998
changed the title
Unsafe enums
RFC: Unsafe enums
Jan 23, 2015
This comment has been minimized.
This comment has been minimized.
|
If you already require |
P1start
reviewed
Jan 23, 2015
| unsafe { | ||
| let Variant1(bar) = foo; | ||
| } | ||
| ``` |
This comment has been minimized.
This comment has been minimized.
P1start
Jan 23, 2015
Contributor
This would be kind of annoying for when you want to only put the minimum number of non-unsafe things inside the unsafe block; you’d have to write something like this:
let x;
unsafe {
let Variant1(bar) = foo;
x = bar;
}
// use `x`because unsafe creates its own scope. I don’t really have a better suggestion, but it’s good Rust style to put only actually unsafe stuff inside unsafe blocks, and this would make that a little harder.
This comment has been minimized.
This comment has been minimized.
retep998
Jan 23, 2015
Author
Member
Perhaps something like let unsafe { Variant1(bar) } = foo;? I'm not sure how feasible that would be to implement though.
If we went with the fancy restrictive trait as suggested by @eddyb then we'd be able to remove the unsafe blocks entirely making the resulting code much more concise.
This comment has been minimized.
This comment has been minimized.
|
@eddyb That is similar to http://discuss.rust-lang.org/t/new-type-kind-rawdata/996. However, I think this is too restrictive as an unsafe enum may need to contain:
|
This comment has been minimized.
This comment has been minimized.
|
You can't call |
This comment has been minimized.
This comment has been minimized.
|
@eddyb: I think you have mixed with So ok an |
This comment has been minimized.
This comment has been minimized.
|
A somewhat more minimalistic idea for addressing the same problem. |
brson
self-assigned this
Jan 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Although there's definitely a missing feature here, I think it's something we can hold off on for a while. I've opened #877 to keep track of it. |
brson
closed this
Feb 17, 2015
This comment has been minimized.
This comment has been minimized.
|
I started a discussion on internals to get a push going for this again |
retep998 commentedJan 23, 2015
Unsafe enums are effectively untagged unions, useful for FFI.
Rendered