As I am setting up my new machine, I came across this error when emacs tried to use rust-analyzer
error: Unknown binary 'rust-analyzer' in official toolchain 'stable-x86_64-apple-darwin'. As mentioned in this SO question, which rust-analyzer did not show any error.1
Luckily, the same SO question also had the solution
I needed to explicitly install it via rustup component add rust-analyzer
Luckily, the comment in the accepted answer also explained why which works.
When refactoring code to make API call to Gemini, I learnt how to format raw strings in rust.
fn main() { let var1 = "test1"; let formatted = format!(r#"var1 is: {}"#, var1); println!("{}", formatted); } This gives output as : var1 is: test1
If you want { in the output, then it needs to be escaped with additional { like:
fn main() { let var1 = "test1"; let formatted = format!
It is very important that secrets are stored in environment variables during the runtime.
During the development, it makes sense to use .env file. In my last project, there were probably 40+ variables in the .env. Although that project was in RoR the idea of .env itself is not new.
But for me, using .env with rust is new.
For my current (self) assignment, I needed to store an API Key.
I had tried switching to tmux for local shell sessions in past, but never truly understood why I might need it.
I extensively used tmux for remote sessions. But why might I need it locally ?
Then slowly I stopped using tmux and switched to wezterm which provided multiple tabs.
Fast-forward several years later.
Recently I came across Zellij. I decided to give it a go.
When I had tried tmux it took some time to get used to the keybinding.
At work, I need to load test new framework I had deployed.
Usually, I work with QA team. They use JMeter (with Azure Load test) for such task.
But today, the QA person was busy with other tasks, and I didn’t want to get blocked.
Since I am learning rust, (nu-shell is built in rust) I remembered that it may be possible to run parallel requests in nu-shell.
and it is!
Clippy is a linter for Rust programming language.
If you are annoyed by the compiler (shouting at telling you how your code is wrong), wait till you install and use clippy 😄
Jokes apart, why I want to use clippy is it tells us about idiomatic rust and can autofix issues (if we tell it to do so)
Couple of fun facts I discovered :
First search result for clippy is not what I was looking for 😄 till I searched for rust clippy clippy can not be installed via cargo install (As I tried initially) (As with rest of the rust ecosystem) there was a helpful error message with solution 😇 error: Clippy is no longer available via crates.
Earlier I wrote about various utilities written in rust. Nu shell is one of the most important of them (It is an entire shell after all, not just single utility)
Installing Turns out I had installed nu-shell earlier, but via macports
and I had forgotten about macports (and nu shell)
Mysterious upgrade failure (Or so I thought) When I installed nu-shell via brew I got the latest version, but nu kept invoking older version.
I continued reading Command Line Applications in Rust
Learnt that testing is easy. Any function that has #[test] above it, will be found (across any files) and used by cargo test
Couple of interesting crates :
exitcode It has quite well defined exit codes. They come from FreeBSD I wish other languages / frameworks had something similar proptest is a property testing framework Based on python’s Hypothesis I need to spend time actually trying this human-panic Generates report file on panic Shows nice (if a bit long) message to the user, asking them to (optionally) email the report file to the developer 🤯 Things to explore:
Today I started reading Command Line Applications in Rust
Even though I have not finished reading “the book”, I am (by now) familiar with enough rust code that reading this book was kinda refreshing.
Few important things I picked up :
{:?} in println! is called debug representation (quite useful for .. debugging 😄) Custom data types can add support for {:?} for debugging and logging, one needs to add a #[derive(Debug) above their definition.