I appreciate that the [[https://www.rust-lang.org/learn][rust-lang.org]] recommends three ways to learn the language. I’m intrigued with [[https://doc.rust-lang.org/stable/rust-by-example/][Rust by Example]], and find that it reads well in an Emacs EWW buffer. I’m also interested in seeing if the [[https://github.com/crazymykl/rust-koans][Rust Koans]] project is complete, as I love that style.
* Getting Started
Let’s curtail the [[https://www.rust-lang.org/en-US/install.html][standard installation]], as I’ve [[https://sourabhbajaj.com/mac-setup/Rust/][read]] I could use =rustup= as it will allow my to switch between versions of Rust without having to download specific packages (otherwise, one would, on the Mac at least, issue a =brew install rust=):
#+begin_src sh
brew install rustup
#+end_src
Use the =rustup= to install the Rust compiler (=rustc=) and the Rust package manager (=cargo=):
#+begin_src sh
rustup-init
#+end_src
To verify, run:
#+begin_src sh
rustc --version
#+end_src
Let’s get the rest of the Rust packages for development installed:
#+begin_src sh
cargo install rustfmt
#+end_src
Install the [[https://rust-analyzer.github.io/][rust-analyzer]] is an Rust LSP server implementation (see [[https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary][these installation instructions]]). For Mac, we’ll do:
The [[https://github.com/brotzeit/rustic][rustic project]] incorporates [[https://github.com/rust-lang/rust-mode][rust-mode]] and provides these features:
- cargo popup
- multiline error parsing
- translation of ANSI control sequences through [[https://github.com/atomontage/xterm-color][xterm-color]]
- async org babel
- automatic LSP configuration with [[https://github.com/joaotavora/eglot][eglot]] or [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]]
The [[https://github.com/grafov/rust-playground][rust-playground]] project can create / cleanup rust scratch projects quickly:
#+begin_src emacs-lisp
(use-package rust-playground)
#+end_src
1. From any mode run =M-x rust-playground= for start a new playground buffer filled with basic template for the package with main function (see the picture below).
2. Add your code then press =Ctl-Return= (it bound to =rust-playground-exec= command). It will save, compile and exec the snippet code.
3. When you played enough with this snippet just run =M-x rust-playground-rm=. It will remove the current snippet with its directory and all files.
** Cargo and Toml
The [[https://github.com/dryman/toml-mode.el][toml-mode]] adds syntax highlighting for [[https://github.com/mojombo/toml][toml files]].
#+begin_src emacs-lisp
(use-package toml-mode)
#+end_src
* LSP
* Technical Artifacts :noexport:
Let's =provide= a name so we can =require= this file:
#+begin_src emacs-lisp :exports none
(provide 'ha-programming-rust)
;;; ha-programming-rust.el ends here
#+end_src
#+DESCRIPTION: Emacs configuration for the Rust programming language.