|
1.
|
|
|
% The Rust Design FAQ
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:2
|
|
2.
|
|
|
This document describes decisions that were arrived at after lengthy discussion and experimenting with alternatives. Please do not propose reversing them unless you have a new, extremely compelling argument. Note that this document specifically talks about the *language* and not any library or implementation.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:7
|
|
3.
|
|
|
A few general guidelines define the philosophy:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:9
|
|
4.
|
|
|
- [Memory safety][mem] must never be compromised - [Abstraction][abs] should be zero-cost, while still maintaining safety - Practicality is key
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:13
|
|
5.
|
|
|
[mem]: http://en.wikipedia.org/wiki/Memory_safety [abs]: http://en.wikipedia.org/wiki/Abstraction_%28computer_science%29
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:16
|
|
6.
|
|
|
# Semantics
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:18
|
|
7.
|
|
|
## Data layout is unspecified
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:20
|
|
8.
|
|
|
In the general case, `enum` and `struct` layout is undefined. This allows the compiler to potentially do optimizations like re-using padding for the discriminant, compacting variants of nested enums, reordering fields to remove padding, etc. `enum`s which carry no data ("C-like") are eligible to have a defined representation. Such `enum`s are easily distinguished in that they are simply a list of names that carry no data:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:27
|
|
9.
|
|
|
```
enum CLike {
A,
B = 32,
C = 34,
D
}
```
|
|
|
type: Plain text
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
represents a space character.
Enter a space in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:36
|
|
10.
|
|
|
The [repr attribute][repr] can be applied to such `enum`s to give them the same representation as a primitive. This allows using Rust `enum`s in FFI where C `enum`s are also used, for most use cases. The attribute can also be applied to `struct`s to get the same layout as a C struct would.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/complement-design-faq.md:41
|