Rust: Improve readability in default arm of match statement
#TIL in #rustlang we can use any variable name (starting with _) in ignore path of match
Continue Reading »
#TIL in #rustlang we can use any variable name (starting with _) in ignore path of match
Continue Reading »After my previous post I came across other ways to “quickly test rust code” Obvious being rust-script It is easy to install via cargo install rust-script (But I had it already installed. I think Espanso installed it, but not too sure) This may be better than rustc because one can define the dependencies in the “script” itself, like : #!/usr/bin/env rust-script //! Dependencies can be specified in the script file itself as follows: //!
Continue Reading »
Recently, I needed to test try some functionality (of getting user’s home
directory) 1
Setting up a throw away project via cargo new
is certainly possible
but seemed overkill.
I was going thru struct Command
in std::process
1
Obviously, I tried the very first code snippet in the rust playground. There is a very convinient ▸ to run the sample code.
The code ran without any errors.
But no output 🤔
Continue Reading »
I have been using Helix as an editor, not as an IDE.
One of the USP of Helix is LSP support out of the box
Recently, I’ve been programming in rust.
Helix is also written in rust.
So I think it is natural that they would support rust LSP rust-analyzer
and it does.
But I wasn’t getting auto completions 😞
Continue Reading »In rust, tests are written in the same file as the code. But I want to have the tests in a separate file. Conventionally, only the integration tests are written in files under tests folder. 1 I just wanted to have the unit tests in a separate file. So I created a file src/my_tests.rs and moved all the tests there. But cargo test kept saying running 0 tests Turns out, I’m not the only one.
Continue Reading »No, this is not a post about how to implement doubly linked list in rust. Or ir could be a very short post, since doubly linked list in built-in the std::collection as LinkedList Following functions are available: new : Creates new/empty linked list push_back : Adds an element to the list push_front : Since this is doubly linked list, element can be added at the beginning as well. Nice! pop_back and pop_front : Remove an element from the list clear : empty the entire list append : Append one list to another to make bigger list.
Continue Reading »I initially tried to turn off the type hints via rust-analyzer extension setting, but that did not work 😞 Turns out it is very complicated (at least for me) documentation did not help 😞 Here is what worked for me. Thanks to SO 1 Open Command Palette Cmd+Shift+P Select Preferences: Open User Settings (JSON) from the drop down Add the following to existing settings Or create new one, if empty. You may need to enclose it within { } though.
Continue Reading »Today, I accidentally found out that instead of using {:?} to debug print, if one just adds an extra # like {:#?} the variable is pretty printed. This makes sense for struct rather than simple data types like numbers or strings. The interesting part (for me at least) is how I “discovered” it 😄 When I was printing a struct (for debugging 🙈) VS Code (I think rust analyzer plugin) showed a popup how the struct does not implement Display 1
Continue Reading »It is (almost) drop-in replacement for pip. We just need to invoke it as uv pip instead of pip How to install ? pipx install uv : This makes it available everywhere. Other alternatives are curl (recommended) and brew (on macOS) It is superfast I tried installing Django $ uv pip install Django Resolved 3 packages in 138ms Downloaded 3 packages in 2.53s Installed 3 packages in 228ms + asgiref==3.8.1 + django==5.
Continue Reading »