24 days of Rust - anymap

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

In this article we will focus on the anymap crate by Chris Morgan of rust-http and teepee fame. This crate provides the AnyMap type - a slightly peculiar, interesting container.

The AnyMap type is different from a regular map. For example, a HashMap in Rust is a generic type parametrized by K - the type of keys and V - the type of values stored in map. (There's also a hasher parameter, but it's not relevant here.) Meanwhile, AnyMap itself is not a generic type. It uses a HashMap internally but we don't need to know that; conceptually, AnyMap maps from types to values. This means that for each and every type there can be at most one value contained in the mapping.

Czytaj dalej »
Napisane 9 grudnia 2014

24 days of Rust - racer

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

Welcome to the second week of 24 days of Rust! Hope you enjoy the articles so far. Today let me introduce you to racer - a code completion engine for Rust.

As there is no proper Rust IDE (yet), most of us Rustaceans use some code editor such as Vim, Emacs, Atom etc. However the out-of-the-box support for Rust is very limited - if you're lucky, your editor has syntax highlighting, but not much more. We'd love to have some sort of autocompletion to ease typing, and a "go to definition" command to quickly jump around the codebase.

Czytaj dalej »
Napisane 8 grudnia 2014

24 days of Rust - itertools

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

The itertools crate contains several utility functions and macros inspired by Haskell and Python itertools. As you can guess from the name, these have to do with iteration and iterators. Rust has recently split the Iterator trait into Iterator and IteratorExt for so called object safety reasons (see the RFC for an explanation). This is mostly irrelevant for today's episode of 24 days of Rust, but worth keeping in mind.

Czytaj dalej »
Napisane 7 grudnia 2014

24 days of Rust - working with JSON

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

JSON is a workhorse data format of the modern Web. Originating from the JavaScript world, it gained a lot of traction and at the moment it's usually the first choice of a Web developer for a data interchange format. Not only Web - once JavaScript-only, JSON support is now ubiquitous. A lot of languages ship with JSON parsers in the standard libraries, and when it's not the case, surely someone has already built a third party library. In case of Rust, JSON support comes out of the box in the serialize::json module.

Czytaj dalej »
Napisane 6 grudnia 2014

24 days of Rust - hyper

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

The state of HTTP libraries in Rust is a constant flux. See Are we web yet? for an overview of the current affairs. There's rust-http which although usable (for example Nickel builds on top of that) is not developed anymore. Teepee, it's conceptual successor, is in the words of it's author not even vaguely usable. Meanwhile a new library emerged during the last few months: hyper, which will be the subject of this blogpost.

Czytaj dalej »
Napisane 5 grudnia 2014