This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be749f3
commit 51685ca
Showing
8 changed files
with
126 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
# Rust empowers by being... | ||
|
||
Rust's [overall goal](./goals.md) is to "empower everyone to build reliable and efficient software". But how do we do that? This section identifies the various things that Rust tries to be in order to empower its users. | ||
Rust's [overall goal](./goals.md) is to "empower everyone to build reliable and efficient software". But how do we do that? This section identifies the various things that Rust tries to be in order to empower its users. If you click on a particular entry, you will find more notes, along with a list of mechanisms that we use (for example, reliability is enhanced by type safety). | ||
|
||
**Note that these goals are often in tension.** For any given design, we always want to achieve (or at least be neutral) all of these feelings. In some cases, though, we may be forced to decide between slightly penalizing one goal or another. In that case, we tend to support those goals that come earlier in the list over those that come later (but every case is different). See the [case studies](./case_studies.md) for examples. | ||
|
||
## [⚙️ Reliable](./how_rust_feels/reliable.md): "if it compiles, it works" | ||
## [⚙️ Reliable](./how_rust_empowers/reliable.md): "if it compiles, it works" | ||
|
||
> One of the great things about Rust is the feeling of "it if compiles, it works". This is what allows you to do a giant refactoring and find that the code runs on the first try. It is what lets you deploy code that uses parallelism or other fancy features without exhausting fuzz testing and worry about every possible corner case. | ||
## [🐎 Performant](./how_rust_feels/performant.md): "idiomatic code runs efficiently" | ||
## [🐎 Performant](./how_rust_empowers/performant.md): "idiomatic code runs efficiently" | ||
|
||
> In Rust, the fastest code is often the most high-level: convenient features like closures, iterators, or async-await map down to code that is at once efficient and which uses minimal memory. | ||
## [🧩 Productive](./how_rust_feels/productive.md): "a little effort does a lot of work" | ||
## [🧩 Productive](./how_rust_empowers/productive.md): "a little effort does a lot of work" | ||
|
||
> Rust and its ecosystem offer a wide array of powerful building blocks that can be combined and recombined. The result is that standing up a quality system can be done in record time. | ||
## [🥰 Supportive](./how_rust_feels/supportive.md): "the language, tools, and community are here to help" | ||
## [🥰 Supportive](./how_rust_empowers/supportive.md): "the language, tools, and community are here to help" | ||
|
||
> We strive to make our tools polished and friendly, and we look for every opportunity to guide people towards success. Part of that is building a community that eagerly shares its knowledge in a welcoming and inclusive way. | ||
## [🔧 Transparent](./how_rust_feels/transparent.md): "predict and control low-level details" | ||
## [🔧 Transparent](./how_rust_empowers/transparent.md): "predict and control low-level details" | ||
|
||
> The translation from Rust to underlying machine code is straightforward and predictable. If needed, you have options to control the low-level details of how your application works. | ||
## [🤸 Versatile](./how_rust_feels/versatile.md): "you can do anything with Rust" | ||
## [🤸 Versatile](./how_rust_empowers/versatile.md): "you can do anything with Rust" | ||
|
||
> Rust scales well both up and down: it is well-suited to building everything from simple scripts to web servers to WebAssembly programs to kernel extensions and embedded systems. It is usable on both common and esoteric platforms. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
# 🏇 Performant: "ran well right out of the box" | ||
# 🏇 Performant: "idiomatic code runs efficiently" | ||
|
||
> > In Rust, the fastest code is often the most high-level: convenient features like closures, iterators, or async-await map down to code that is at once efficient and which uses minimal memory. | ||
> In Rust, the fastest code is often the most high-level: convenient features like closures, iterators, or async-await map down to code that is at once efficient and which uses minimal memory. | ||
## In tension with | ||
|
||
Making Rust feel performant can be in tension with Rust feeling [supportive], and in some cases [productive]. The problem is that making abstractions efficient may mean that they aren't able to provide some of the niceties that users are accustomed to from other languages. Less obvious is that feeling performant can be in tension with feeling [transparent] or [versatile]; this is because many optimizations rely on a lack of transparency about the precise order or way in which things happen, and having more visibility, or more choices, can make those optimizations harder to do. | ||
|
||
[supportive]: ./supportive.md | ||
[productive]: ./productive.md | ||
[versatile]: ./versatile.md | ||
[transparent]: ./transparent.md | ||
|
||
## Examples | ||
|
||
### Iterators | ||
|
||
Rust iterators are a good example of something which meets our goal of being *performant*. Code that uses iterators not only feels higher-level, it often compiles down to loops which are more efficient than if you wrote the loops with explicit iterators. This is because iterators are able to skip bounds checks on vectors. | ||
Rust iterators are a good example of something which meets our goal of being *performant*. Code that uses iterators not only feels higher-level, it often compiles down to loops which are more efficient than if you wrote the loops with explicit iterators. This is because iterators are able to skip bounds checks on vectors or take other shortcuts. | ||
|
||
## Mechanisms | ||
|
||
What are some of the ways that we make Rust feel **performant**? | ||
|
||
### Zero-cost abstractions | ||
|
||
Rust borrowed the idea of zero-cost abstractions from the C++ community. Bjarne Stroustroup defined zero-cost abstractions as, "What you don't use, you don't pay for. And further: What you do use, you couldn't hand code any better." We design our abstractions with these goals in mind as well. | ||
|
||
### Async-await | ||
### Avoid overspecifying machine details | ||
|
||
The goal with async-await syntax is to make a convenient, accessible way to write code which compiles down to the same sort of state machines that C programmers have been writing by hand to create event-driven architectures. | ||
Many details of Rust are left deliberately unspecified. For example, unless users manually add a `repr` attribute, Rust structs and enums can be laid out in memory however the compiler sees fit. This allows us make optimizations like reordering struct fields to eliminate padding and reduce size, or representing `Option<&T>` as a single, nullable pointer. (Of course, reserving this freedom works against [transparency] and [versatility], which is why we have the option to specify the `repr`.) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
# 🥰 Supportive | ||
# 🥰 Supportive: "the language, tools, and community are here to help" | ||
|
||
> We strive to make our tools polished and friendly, and we look for every opportunity to guide people towards success. Part of that is building a community that eagerly shares its knowledge in a welcoming and inclusive way. | ||
## In tension with | ||
|
||
Making Rust feel supportive can be in tension with Rust feeling [reliable]. It may also be in tension with Rust feeling [versatile]: often the most supportive path is to offer a simple, streamlined set of choices, but that may be too limiting. | ||
|
||
[reliable]: ./reliable.md | ||
[versatile]: ./versatile.md | ||
|
||
## Mechanisms | ||
|
||
What are some of the ways that we make Rust feel **supportive**? | ||
|
||
### Polished developer experience | ||
|
||
Rust tools strive to provide a polished, smooth experience for our developers. One example is how the compiler offers quality error messages that attempt to not only indicate an error, but to teach the user how the language works, and offer helpful suggestions for how to fix their code. For tools like cargo, this manifests in careful CLI design that makes the "easy things easy" (but of course, for Rust to feel [versatile], we have to go beyond that). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
# 🔧 Transparent | ||
# 🔧 Transparent: "predict and control low-level details" | ||
|
||
> The translation from Rust to underlying machine code is predictable. If needed, you have options to control the low-level details of how your application works. | ||
> The translation from Rust to underlying machine code is straightforward and predictable. If needed, you have options to control the low-level details of how your application works. | ||
## In tension with | ||
|
||
Feeling transparent can be in tension with [supportive] or [productive], because transparency often requires exposing details. | ||
|
||
[supportive]: ./supportive.md | ||
[productive]: ./productive.md | ||
|
||
## Mechanisms | ||
|
||
What are some of the ways that we make Rust feel **transparent**? | ||
|
||
### No global costs | ||
|
||
Rust strives to avoid features that impose global costs (that is, impose a runtime cost even on projects that don't use them). This is a key part of Stroustroup's definition of [zero-cost abstractions](./transparent.md#zero-cost-abstractions), "What you don't use, you don't pay for". This is the mechanism that encourages us to use ownership instead of a garbage collector, for example, since a garbage collector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# 🤸 Versatile | ||
# 🤸 Versatile: "you can do anything with Rust" | ||
|
||
> Rust can be used to build everything from simple scripts to web servers to WebAssembly programs to kernel extensions and embedded systems. Rust gives you the ability to control low-level details and exposes the capabilities of the underlying system. | ||
> Rust scales well both up and down: it is well-suited to building everything from simple scripts to web servers to WebAssembly programs to kernel extensions and embedded systems. It is usable on both common and esoteric platforms. | ||
## In tension with... | ||
|
||
Feeling versatile can be in tension with feeling [supportive] and [productive]. | ||
|
||
[supportive]: ./supportive.md | ||
[productive]: ./productive.md | ||
|
||
## Mechanisms | ||
|
||
What are some of the ways that we make Rust feel **versatile**? | ||
|
||
### Expose all system capabilities | ||
|
||
We aim to expose all the core system capabilities to Rust programs in some way, even if accessing them or using them correctly can be difficult. We don't want Rust users to feel they have to "drop down" to C or some other language; they should be able to use unsafe Rust to get their job done. Features like "inline assembly" are following in this vein. | ||
|
||
An example of this mechanism in action is `repr(C)`. Although our default struct layout is not defined () |