At first, I assumed since we’ve declared the capacity upfront, it would be maximum capacity of the Vec
Turns out, since Vec is expected to shrink and grow, as needed, there is no maximum capacity for Vec
It just ensures that “sufficient” memory is allocated to the Vec, such that memory reallocation is not required.
On the other hand, if you need more that what you declared with with_capacity, you will get it, but there will need to be reallocation (of memory), so it will be inefficient.
Today I learnt that certain rust code can be marked such that it is compiled only for specific platform.
This makes sense for low level libraries that provide platform-specific functionality that is not available on other platforms.
This is achieved by tagging the function with #[cfg(target_os = "xyz")]
Here xyz can be one of the following :
“windows” “macos” “ios” “linux” “android” “freebsd” “dragonfly” “openbsd” “netbsd” Similar to target_os, here are other options :
Put @microblog.desipenguin.com@web.brid.gy in the search box.
Thanks to Bridgy.fed this site automatically gets it’s own mastodon account.
Following this account is like subscribing to the RSS feed (I think π)
Few days ago, I heard about this on some podcast (maybe changelog ? π€·ββ)
I have been using similar notation for my commits - even for this blog1 - but I did not know it is a specification.
The idea is that very first word of the commit message should indicate what sort of commit is it.
Most common ones are : fix, feat (To indicate bugfix and a feature)
Other useful ones are: docs, style, refactor, test
Then there is chore (catch all ? π)
I’ve used some of these at work as well.
As the website mentions, benefit of such style is that some tools can parse the git log to automatically generate the changelog.
Website also mentions, that
itβs not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
Since the commits are just addition or updates to markdown files, most of the tags are not used here. I only use Add and occasional Update. I do believe it is in the spirit of conventional commits π ↩︎
At least for floating point numbers, it does not crash/panic! π€·ββ
fn main() { let x = 10.0; let y = 0.0; println!("{:?}", x/y); } This above code returns inf
But if we change the number to int, compiler catches this 1 at shows the following error:
error: this operation will panic at runtime
This is a contrived example. Instead of static values, if these were passed at runtime, it would (should?
One of the strength of Rust is memory management. This also leads to compiler errors related to move or borrow When we assign an existing variable to new variable, two things can happen.
Either the data is copied - in that case we can use both old and the new variable without worry. 1
Or data is moved - now we can only use the new variable, as the old variable is “out of scope”.
(undocumented?) Zellij Keybindings Undocumented, because these don’t show up in the default configuration, which shows (I assume) most useful key bindings. I had to look for these, and found them in Github discussions/issues.
Ctrl p d Ctrl p is for pane, but d after that (which I assume stands for down) is not documented. This creates a new terminal in horizontal split fashion 1 Ctrl n - to reduce the size of the terminal.
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.