Naming things is a notorious task as a developer and it’s a constant struggle. I often have two or more browser tabs open in order to find the words I’m looking for. And then one day it hit me.
Wouldn’t it be nice to have a synonym searcher in the terminal?.
With no time to waste, all other side-projects were abandoned in an instant and my path to a better named world began.
It’s always good to begin by figuring out what we want to achieve.
In the spirit of trying to finish this, let’s try to keep the scope relatively…
I’ve been looking at web-scraping for a side project of mine and thought I’d have a look at what Rust has to offer. I found the select crate, which seemed to have all right stuff.
Now I just needed some website for target practice 🎯.
I was reading an article on the Associated Press’s website at the moment so…
The news it is!
With tools and target set, let’s try digging out some information from the data soup called HTML 🍲.
So what do we have to work with?
A quick peek at the top-level modules reveals some main concepts.
I was reading about the PhantomData type and came across the point made that it can be used as a mechanism for controlling lifetimes. From here I started to play around with it a bit and came up with something interesting.
The example itself might be a bit awkward, but bare with me :)
In the example below, we have two threads, one reading (Reader) from a file every 100 milliseconds and one writing (Writer) to a file with some pauses in-between writes. The Reader and Writer are independent and have no knowledge of each other.
When the Reader is…
I was browsing through the Rust standard library and came across PhantomData. I didn’t know what it was used for, so I started reading more about it.
Rust won’t allow you to declare a type parameter without using it. The solution is PhantomData. The PhantomData type can be used in situations when you really don’t need to store the value of something but rather, just the type. There are some examples in Rust’s documentation, but I thought I’d try one out for myself.
Let’s say you want to land on Mars and you have three teams, the Sensor, Thrust and…
The select statement in Go makes it pretty easy to have multiple tasks compete against each other. Which ever channel returns first wins and you get to work with the result. There are many examples of how to do this in Go and all you need is already built in. Figuring out how to do the same in Rust can be more of a puzzle.
Let’s say you want to read some user input from the terminal but timeout if the user takes more than X amount of seconds to do so. It would look something like this in Go.
A few nights ago I stumbled upon this thread on reddit, discussing database migrations.Part of the discussion focused around a zero-downtime strategy.
After this I really just wanted to do this myself — so a few hours later and I had a toy example.
I’ll write about the example I’ve created and won’t focus too much on the nitty gritty details in each blog/video. Follow the links if you want more :)
Pre-requisites for following along…
A fixed-size array, denoted [T; N], for the element type, T, and the non-negative compile-time constant size, N.
This is what you find when you read the first few lines of the documentation about the array type in Rust.
Let’s go through this piece by piece.
To begin with we have the following
A fixed-size array …
Alright, so now we know that the array will never grow or shrink in memory. If you create an array with the capacity to hold 5 elements of the type bool it will forever be an array that can hold 5 bools.
… a little bit of everything :)