Imagine a logging system where we have many threads producing log events, and we have a single thread that consumes those log events and outputs them somewhere. A simple implementation for this would use a Mutex<VecDeQueue> , or perhaps a ring buffer if you are feeling fancy, so that producers can append events at one end and the consumer can pop them off the other, preserving the order. In many…
I first tried Jujutsu earlier this year, but could not get it to stick. One of the main pain points was the lack of accurate documentation. Since then, the documentation has got a lot better, and I have adopted Jujutsu for most of my daily work, and I think it is the best Git interface currently available. This might come as a surprise, as Jujutsu is generally a distinct VCS from Git. The key here…
Making one-off contributions to projects hosted on GitHub is surprisingly onerous, requiring first forking a repository into one’s own account, then cloning it to one’s local machine, making the suggested change, pushing the change, and finally opening a pull request. Afterwards, one is left with a mostly useless fork repository. When Linus Torvalds invented Git in 2005 to facilitate work on…
Both the most popular Rust HTTP client reqwest and the probably most popular web framework axum are built on top of hyper , a low-level HTTP library. hyper itself does not support TLS, which is needed to make HTTPS requests or serve them, but rather provides an interface that allows users to bring their own TLS implementation that fits their requirements. As a consequence, reqwest has a whole…
In Rust, it can sometimes be convenient to add a method to a preexisting type. Rust allows us to implement a trait for a type as long as we own either the trait or the type. This means we cannot implement Iterator for u32 , but we can implement Iterator for MyType , and we can implement MyTrait for u32 . The former is very common, either through the derive macro like #[derive(Copy, Clone, Debug)]…
It is that time of the year again, new headcount is approved, you are going to hire some software engineers. A meeting is called to refresh the interview process. Someone asks “but how are we going to prevent candidates from just using ChatGPT to pass the interview” and everyone murmurs in assent. If you are worried about software engineering candidates using LLMs to pass your technical…
Something I see somewhat regularly when engineers adopt Rust, almost regardless of their level of experience, is the confusion between &str and String . To add to the confusion, both are used in different situations, one of them can transparently convert to the other under the correct conditions, and there is generally an optimal choice to be made. An important fact to notice is that &str is a…
The just concluded edition of Advent of Code included a problem that involved the number of digits of an integer. The naive solution many folks reach for is printing the number to a string and checking the length of the string: fn digits ( n : u64 ) -> u32 { n. to_string ( ) . len ( ) as u32 } My solution used a logarithm with base ten instead, which I deemed more elegant: fn digits ( n : u64 ) ->…
A bit over a decade ago, Gary Bernhardt published Functional Core, Imperative Shell . His proposed software architecture uses functional programming style, especially immutable data, for the bulk of the logic, and an outer shell that uses imperative programming style for side effects such as I/O. This makes it easier to understand, test, and change the logic without imposing the difficulties…
When talking to folks new to the Rust language, a common misconception I encounter is that ? is some kind of special syntax that only works for Result . While it is true that the ? operator is a special bit of syntax, it is not limited to Result , and a lesser known fact is that it works for Option as well: fn maybe_double ( v : Option < u32 > ) -> Option < u32 > { Some ( v ? * 2 ) } In fact, ? is…