Peek-a-boo Rust!

Preethi KR

2 min read

What’s life when there’s no adventure? “Boring Routine”.

Out of college, a year into full-time employment — thirst for adventure took a new paradigm.

“Adventures in Rust”

I’m starting this series with my Partner-in-Science to record everything that we encounter in Rust, just to look back and laugh at ourselves few years down the lane. 😀

We came across this HN article, an interactive web server that runs in the shell. “Pretty cool”, we thought. Now, what would it take to build a web server on our own was the next thing that hit us.

We always wanted to have a side project to hack on everyday after work and this seemed to be interesting.

Now that we’ve found something to work on, the next thing was to figure out what language we’re going to be using. For this project we wanted to use something that we had not used before and something that would introduce us to a new paradigm or programming model. Since our day job was building Rails applications, Ruby (and other similar scripting languages), was out of contention.

We had some interest in Clojure, but since functional programming and lisp in general was foreign to us we did not want to go down that road. Besides we did not want to be dealing with Java libraries and error when doing Clojure.

And then there is “Go”, the new buzz language of the industry. We had already used “Go” for writing a small service in one of our work projects and did not exactly enjoy the experience, although it served the purpose it meant.

Rust was the next candidate and it sort of felt right to start building our web server with Rust since it is a light weight, statically typed, compiled language (which would be something very new for us given our background) and we’ve read about its unique features that ensure memory safety and the zero-cost abstractions it provides and always wanted to see what these meant in the real world.

“Memory Safety”, the term that made us consider Rust a serious option.

So Rust it was.

Baby steps…

We started off downloading Rust into our Linux machine which was pretty easy and quick. We got access to the compiler –rustc and cargo ,which is the feature packed build tool for Rust that also handles package management.

Almost everything we encountered in Rust, we tried to relate it to our everyday work language — Ruby.

And now it was time to write the customary “Hello, World” app. Compiling and running the app with rustc reminded us about compiling and running C programs in college. *The days we never fully understood what we did!*

Next we dug into the Documentation of the language and ran into “The Rust book” — which is supposed to be the go-to resource for getting started with Rust.

The book taught us how to use cargo to setup a new Rust project. Doing this we encountered a totally new markup language called toml(Tom’s Obvious, Minimal Language) in which the cargo.toml is written, and is used to configure the Rust project and specify its dependencies. cargo then uses this to pull all the required dependencies for us and maintains a cargo.lock file which is very similar to what bundler does with the Gemfile.lock in the Ruby world. That’s where the similarity ended for us between Rust and Ruby as we moved on through the Rust book.

The book explained the basis of the language by building an implementation of the “Guessing Game” in Rust. That’s how we started with Rust.

We’ll keep adding more stories to this series every week, as we increase the developments to our web server.

Incase, you want to see how our project is turning out, here’s a secret link to our Github repo. (Yay! As of 21.03.2017, we’ve got a static File server ready) **BIG SMILES**

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *