Rocket and Rust Part II (and Midnight Orange)

Now that I have Rust running locally and a basic understanding of Rust from going through the Tour of Rust, I want to build something more substantial. I knew from the beginning I wanted to build some kind of web application, given my background in web app development. I looked a few options to pursue my goals: Yew, pure Web Assembly (compiling Rust to WASM), and others. The decision came down to whether I wanted something pure front-end, or if I wanted a back-end web application written in Rust. I decided to try one of the back-end focused frameworks and as the title implies, I decided to give Rocket a try.

My decision came down to reading some interesting articles, including one on Medium called "Creating a Rust Web App with Rocket and Diesel". The ergonomics reminded my of other frameworks I have used, at least with the ease of routing syntax. The easy incorporation of a possible data connection using Diesel was also very attractive. I will also point out Rocket's documentation is very very good (although, similar to my first article in this series, I definitely did not read something well enough).

Alright, well, let's Get Started with Rocket's guide. I already have Rust installed, so I skipped over the first section. I ran the cargo commands to create my new project, as mentioned in Rocket's docs:

cargo new hello-rocket --bin
cd hello-rocket
Using cargo to create a new project 

I added the rocket crate to my Cargo.toml file:

[dependencies]
rocket = "=0.5.0-rc.3"
Adding rocket dependency to Cargo.toml

I then modified my src/main.rs to contain the Hello World code from the Rocket Getting Started guide:

#[macro_use] extern crate rocket;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![index])
}
Rocket hello world example from Rocket's documentation

Sweet! So easy! Now to just run cargo run to start my server and go to localhost... Wait. What? Instead of the lovely output Rocket's documentation said I should see, and my magical server startup, I see a wall of red in my terminal. Uh... Okay. I go through all the steps again. Try to run the application. Same issue. At this point, I call in my reinforcement rubber duck (aka Nick). I walk him through everything I did and the result. At this point... I will be honest. I am a bit miffed.

Well, similar to my last issue (a mistype on the rustc command where I left off the "c"), my current problem was mismatch in what I was supposed to type vs. what I did. To preface, I am using Visual Studio Code as my editor of choice. I installed some recommended Rust plugins for ergonomics, one of which is the "crates" plugin by Seray Uzgur. When I added the rocket crate dependency to my Cargo.toml, the plugin listed all the versions. I, without thinking about all of Rocket's documentation targeting their 0.5 release candidate (RC), simply let it select the latest published version of Rocket. The version I installed accidently was actually 0.4.11 and not the RC version 0.5.0 which the documentation is all referring to. Proceed to infinite facepalm. 🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️🤦‍♀️

So what did I learn? Well, I again learned the value of talking through the steps I have taken with someone (rubber duck). I, again, am reminded I sometimes move to fast and do not take the time to double check each individual part (I thought something was wrong with my rust install again which was a red herring in this case). Finally, I learned to not assume a plugin, especially one I just started using, is going to do what I want. While the plugin is certainly handy (thanks Seray!) I may stop using it at least for this project: I don't like it yelling at me about using an RC package when so much of Rust is bleeding edge still.

Okay okay. We now have the corrected crate dependency. We attempt to run our hello world again and wait with bated breath....

Screenshot of working hello world
Screenshot of working cargo run and Rocket route

Yay! Much rejoicing was had! We managed to get our first rocket application working and our server running for our application. Next time, on Rocket and Rust, I will start talking about the actual project I am planning on creating for my first foray into Rust (and Rocket). But first...

A Special Bottle Consumed

I am a sucker for Goose Island Beer Co.'s Bourbon County Stouts. I have been drinking them for years, usually buying a couple of each release to keep for a couple of years before consumption. The other day, I decided to break into the stash. I poured the Midnight Orange Stout from 2018 into a glass and enjoyed.

These beers always share a few things in common regardless of the year or specialty release: they are rich, smooth, and full of delicious chocolate malt flavors. The Midnight Orange was no exception and had an added orange zest and sweet orange flavor. It reminded of those chocolate oranges you can buy around the holidays: the ones you whack on something to break apart the segments. The beer wasn't as sweet as the milk chocolate version, but perhaps similar to the dark chocolate ones.

Overall, I loved this beer as much as the others. I don't know how they don't end up a syrupy mess, but the high alcohol content (this one clocked in at 15.2% ABV) seems to help balance the sweet notes and prevent them from being overpowering. Cheers, folks, and don't let anyone tell you not to drink dark beer in the summer!

Picture of Midnight Orange beer in a glass outside.