24 days of Rust - winreg

Fact: I'm writing these articles and examples on a Windows machine and so far everything compiles and works as expected. Just so you know, Rust supports Windows in the top tier. I'm mentioning it here since a few people I talked to assumed Windows support was sort of secondary, bolted-on later. This is not the case.

The library ecosystem also supports different operating systems fairly well. There are even cross-platform crates for stuff usually associated with Linux, such as curses or coreutils. However, some crates support only Linux or Windows by design. One of them is winreg - a Rust API to access Windows Registry.

Continue reading »
Written on Dec. 8, 2016

24 days of Rust - serde

Two years ago I wrote an article about working with JSON in Rust. JSON (de)serialization support was then baked in the standard library. However, at that time Rust was at version 0.13 and a lot of things happened since then. Mainly, the rustc-serialize crate got pulled out of the core libraries, but kept its close relation to the rustc compiler itself. (Hence the slightly awkward name.)

Meanwhile, a new contender arose: serde. It is also a generic serialization framework for Rust. It's more modern, actively maintained and gets lots of love from the community. There's a selection of supported data formats, including JSON, YAML, MessagePack as well as several others. Even the official docs for rustc-serialize say (emphasis mine):

While this library is the standard way of working with JSON in Rust, there is a next-generation library called Serde that's in the works (it's faster, overcomes some design limitations of rustc-serialize and has more features). You might consider using it when starting a new project or evaluating Rust JSON performance.

Continue reading »
Written on Dec. 7, 2016

24 days of Rust - static initialization

Static variables are available throughout the entire life of a program. They are allocated in a block of memory known at compile time. Due to that, they tend to represent global state that the program can access. It's getting especially tricky if one static variable depends on another. Some language communities even talk about static initialization order fiasco (looking at you, C++). Other, like C, allow static intialization only with constant literals/expressions. Rust belongs to this group as well. But there are alternatives...

Continue reading »
Written on Dec. 6, 2016

24 days of Rust - environment variables

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.

That's Wikipedia. Let's read it again. Dynamic - because they can change. Named - because like any other variables, they have names. Affect processes - this is the most important part. Environment variables tell the program in what context it is running - what's the current language, where is user's home directory etc. They can also store configuration for the process. For example, a popular cloud hosting platform (Heroku) exposes configuration values to the app as environment variables.

Continue reading »
Written on Dec. 4, 2016