rust-mode alternatives and similar packages
Based on the "Emacs" category.
Alternatively, view rust-mode alternatives based on common mentions on social networks and blogs.
Do you think we are missing an alternative of rust-mode or a related project?
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> Table of Contents
- Feature guide
- Other recommended packages
- For package maintainers
<!-- markdown-toc end -->
This mode provides:
- Syntax highlighting (for Font Lock Mode)
- Integration with Cargo, clippy and rustfmt
This mode does not provide autocompletion, or jumping to function / trait definitions. See Auto-completion / code navigation below for tips on how to enable this.
The package is available on MELPA. Add this to your init.el.
(require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (package-refresh-contents)
Now you can install
M-x package-install rust-mode
And put this in your config to load rust-mode automatically:
Clone this repository locally, and add this to your init.el:
(add-to-list 'load-path "/path/to/rust-mode/") (autoload 'rust-mode "rust-mode" nil t)
Commands like TAB should indent correctly.
The Rust style guide recommends spaces rather than tabs for indentation; to follow the recommendation add this to your init.el, which forces indentation to always use spaces.
(add-hook 'rust-mode-hook (lambda () (setq indent-tabs-mode nil)))
rust-format-buffer function will format your code with
rustfmt if installed. By
default, this is bound to C-c C-f.
rust-format-on-save enables automatic formatting on
save. For example, add the following in your init.el to enable format
(setq rust-format-on-save t)
Running / testing / compiling code
rust-check functions shell out to
Cargo to run, test, build and check your code. Under the hood, these use the
These are not bound by default. To bind these to keyboard shortcuts, you can use the following in your init.el:
(define-key rust-mode-map (kbd "C-c C-c") 'rust-run)
Clippy, a linter.
Easy insertion of !dbg
rust-dbg-wrap-or-unwrap either wraps or unwraps the current region
dbg!. This can be useful for easily adding debug lines to your
This is bound to C-c C-d by default.
Other recommended packages
Auto-completion / code navigation
This package does not provide integration with RLS, which provides auto-completion and code navigation. To use this you need an Emacs package that supports LSP.
Two examples are:
flycheck allows highlighting compile errors and Clippy lints inline.
cargo.el provides a minor mode for integration with Cargo, Rust's package manager.
rustic is a fork of rust-mode, extending it with other features such as integration with LSP and with flycheck.
For package maintainers
rust-mode-tests.el contains tests that can be run via
You can use
run_rust_emacs_tests.sh to run them in batch mode, if
you set the environment variable EMACS to a program that runs emacs.