Rust is a systems programming language without a garbage collector focused on three goals: safety, speed, and concurrency. Use this tag for questions about code written in Rust. Use an edition specific tag for questions that refer to code which requires a particular edition, like [rust-2018]. Use more specific tags for subtopics like [rust-cargo] and [rust-macros].
Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without needing a garbage collector, making it a useful language for a number of use cases other languages aren’t good at: embedding in other languages, programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems.
It improves on current languages targeting this space by having a number of compile-time safety checks that produce no runtime overhead, while eliminating all data races. Rust also aims to achieve ‘zero-cost abstractions’ even though some of these abstractions feel like those of a high-level language. Even then, Rust still allows precise control like a low-level language would.
Try Rust online in the Rust Playground
The Rust Playground is an online application that allows you to experiment with Rust by editing and running Rust code from the comfort of your browser; no need to install Rust locally! Several crates (Rust's reusable libraries) are available in the playground to showcase some of Rust's ecosystem.
Version
After a long period of iteration and experimentation, Rust 1.0 shipped on May 15th, 2015. This release is the official beginning of the Rust language's commitment to stability, and as such it offers a firm foundation for building applications and libraries. From this point forward, breaking changes are largely out of scope (some minor caveats apply, such as compiler bugs).
Rust employs three release channels: stable, beta, and nightly. Every six weeks the beta channel is released as a stable version and the current nightly channel becomes the beta candidate.
Edition
Even though Rust commits to stability, editions are used to introduce changes that would be breaking (new keyword for instance). Every version of the compiler supports every edition introduced before its release. You just mark your crate with the edition you want to target and you get the feature of this edition.
Currently, there are three editions: 2015 2018, and 2021. Find out more in the Edition Guide.
What does it do?
Rust supports a mixture of programming styles: imperative procedural, concurrent actor, object-oriented and functional. It supports generic programming and meta-programming, in both static and dynamic styles. Rust is also capable of creating bindings for C foreign function interfaces.
The language design pursues the following goals:
- Compile-time error detection and prevention.
- Clarity and precision of expression.
- Run-time efficiency.
- High-level zero-cost abstractions.
- Safe concurrency.
Standard Library
You can view what the standard library has to offer, and search through it, here. The scope of the standard library will continue to grow in future versions of the language.
Getting Started
To get started with the language:
- Start with the book.
- Open up the standard library documentation.
- Read Rust by Example.
- When you are ready for the deepest and darkest arts of Rust, dive into The Rustonomicon.
To help your memory, there is a cheat sheet with references to these books.
You can find a lot more learning resources (including non-English ones) in the rust-learning
repository or in the rust-unofficial
repository.
Getting Help
Not all questions are suitable for Stack Overflow, and discussions certainly are not. If you wish to ask for a recommendation for an IDE, a library, or wish to discuss about the best way to organize a bit of code, then you may consider alternative venues.
More open-ended questions and discussions are welcome on:
- the Rust-Beginners IRC channel,
- the Rust subreddit,
- the Rust users forum.
There is a list of Rust IRC channels on the community page, and there are even language-specific channels if English is not your forte.
Additionally, the AreWeXYet collection of websites provide helpful summaries and lists of thematic resources:
Producing a Minimal, Reproducible Example (MRE) for Rust code
Questions on Stack Overflow that seek debugging help ("why isn't this code working?") must include the shortest code necessary to reproduce it in the question itself. Without it, the question is off-topic and is likely to be closed. Here are some common points to follow to reduce your code to create a good MRE:
Try to run your code in a different environment.
- On the Rust Playground
- In a separate Cargo project
If your code fails to compile, include a copy of the error message, preferably complete and unmodified from the compiler's output.
Remove unused
- crates
- modules
- types
- enum variants / members
- struct members
- function arguments / return values
Combine multiple modules into a single file by rewriting
mod foo;
asmod foo { /* contents of foo.rs */ }
Replace complete or partial statements or entire function bodies with the macro
unimplemented!()
.Replace booleans with hard-coded
true
orfalse
valuesRemove containing loops and conditional flow statements.
Remember that some steps might "unlock" other steps; try to apply each step in turn until no steps can be followed! Ensure that your error continues to occur after each change to avoid going down the wrong path.
There's also some information that you should provide about your code:
It will be assumed that you are using the current stable version of Rust. If you are not using this version of Rust, state your version. This can be found by running
rustc --version
.If you are using crates, state the versions of every crate that you are using. This can be found in your Cargo.lock file.
Books
Code Editors & IDEs:
- Atom (Rust language support)
- Eclipse (plugin)
- Emacs (plugin)
- GNU Emacs (Rust-mode)
- Geany IDE (Rust Language support out-of-the-box)
- Gnome Builder (Rust Language support out-of-the-box)
- InteliJ IDEA (plugin)
- LightTable (plugin)
- Sublime Text (Sublime Text package for Rust)
- Vim (Rust.vim)
- Visual Studio Code
- Recommended: rust-analyzer
- Legacy: The Rust extension (deprecated) or vscode-rust
- Visual Studio (Visual Studio extension for Rust)
For a comparison of editors' features, see: Text editor features overview (Syntax highlighting, Snippets, Code Completion, Linting, Go-to Definition, Syntax Checking).