About Rust
parent
68d4de8c1b
commit
05008b4e76
@ -0,0 +1,44 @@
|
||||
#+BLOG: arenzanaorg
|
||||
#+POSTID: 438
|
||||
#+DATE: [2022-01-11 Tue 16:30]
|
||||
#+OPTIONS: toc:nil num:nil todo:nil pri:nil tags:nil ^:nil
|
||||
#+CATEGORY: emacs,dev
|
||||
#+TAGS[]: tech
|
||||
#+DESCRIPTION:
|
||||
#+TITLE: 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](https://arenzana.org/posts/2019-12-03-emacs-go-mode-revisited/) development set ups that made it all quite simple.
|
||||
|
||||
* 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~):
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package rust-mode
|
||||
:defer t
|
||||
:ensure t
|
||||
:init
|
||||
(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))
|
||||
#+end_src
|
||||
|
||||
Here, we load the mode for Rust development. Auto-indent with spaces, run ~rustfmt~ on save (needs to be installed via [rustup](https://rustup.rs/). 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.
|
||||
|
||||
* 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.
|
||||
|
||||
|
Loading…
Reference in New Issue