The beginning of learning Rust

Last updated: 2018-03-01

Background:

I wanted to learn rust, a systems programming language developed by Mozilla. The only problem was that I was struggling for ideas for projects.

I came across a post on Reddit about someone recommending that people should make a static site generator as a project when they learn a new language.

I was rather apprehensive at first, because I felt that something that was above my current capabilities.

But once I divided up the project into a lot of small pieces, it became much less overwhelming.

Development:

I found some libraries that really helped speed up development, so that wouldn't have to implement some of the more hairier portions of static site generating(like generating html from markdown and converting json data into html templates). These libraries were comrak and askama.

Learning Rust has been one of the more interesting things I have done in a while. It's interesting approaches to how it deals with memory management and mutable variables make it quite the challenging language to someone coming from doing a lot of JavaScript/es6/React. Having not touched much Java since college, a typed language is rather refreshing.

I wanted to point out some tricky concepts for those also learning Rust that also confused me(and still do sometimes).

The <'a> is what's known as a lifetime construct. In Rust, the language is very careful about what it will let you do in regards to reusing variables all over the place. The lifetime construct tells Rust how long you want the variable to last.

Lifetimes are also part of Rust's borrowing checking. In Rust, you have to borrow variables you want to use in a function or in some other activity. Using & means you're borrowing a variable. In the case below, I'm borrowing the strings used for the data in my static site.

[object Object]