Browse Source

Rust dev

Ismael Arenzana 4 months ago
Signed by: isma
GPG Key ID: D5586DE2A32CBC3C
  1. 46
  2. 3


@ -0,0 +1,46 @@
# Emacs for Rust Development
## Emacs > Visual Studio Code
There's a good chance I'm a hater or that I don't know what I'm doing. After a couple of hours trying to set up VS Code for Rust development, I ended up frustrated not understanding how to simply call the compiler or the debugger from the interface. I looked for `rust-mode' on Github and 15 minutes later I was up and running on Emacs. Maybe it's my previous experience with Go development[1] set ups that made it all quite simple.
=> [1] Go development (HTTPS)
## Rust on Emacs
I approached this the same way I approached Go: let's get regular syntax highlighting, linting, formatting, and compiling first and we'll worry about debuggers later. I'm a bit old school when it comes to approaching debugging. We end up with the following on the Emacs config (if you use `use-package'):
(use-package rust-mode
:defer t
:ensure t
(add-hook 'rust-mode-hook
(lambda () (setq indent-tabs-mode nil)))
(setq rust-format-on-save t)
(add-hook 'rust-mode-hook
(lambda () (prettify-symbols-mode)))
(add-hook 'rust-mode-hook #'lsp)
:bind (("M-," . rust-compile))
(use-package flycheck-rust
:ensure t
:hook (flycheck-mode-hook . flycheck-rust-setup))
Here, we load the mode for Rust development. Auto-indent with spaces, run `rustfmt' on save (needs to be installed via rustup[1]). Prettify symbols (cause why not), and use language server protocol. I'm binding "M-," to compile; I know it's an odd keybinding, but I'm used to it by now. Feel free to make it your own.
In addition to this, I'm hooking `flycheck' for linting.
=> [1] rustup (HTTPS)
## Conclusion
IntelliJ made it very easy to set up as well, but that's a multi-hundred dollar application. If you're on a budget, Emacs, vim, or VSCode should bet viable options as well.
I'm still getting started with Rust and I don't know how much it will stick, since I've been writing Go for a number of years; but I'm happy I have a familiar environment to get started from. By now I should know Emacs should *always* be my first option.


@ -34,6 +34,7 @@ B2AD 040F 88EC 812F 6ABB 8392 E855 12E7 12CC D0C6
## Articles
=> 2022-01-11-emacs-rust.gmi [20220111] - Emacs for Rust Development
=> 20210201-farewall-whatsapp.gmi [20210201] - Farewell, Whatsapp
=> 20200819-emacs-27-1-install.gmi [20200819] - Emacs 27.1 Install
=> 20200624-emacs-server-mode.gmi [20200624] - Emacs Server Mode
@ -46,4 +47,4 @@ B2AD 040F 88EC 812F 6ABB 8392 E855 12E7 12CC D0C6
=> 20190120-emacs-lovely.gmi [20190120] - Emacs, Lovely
=> 20181120-hello-world.gmi [20181120] - Hello World!
© 2021 All Rights Reserved
© 2022 All Rights Reserved