This blog is a static site that is currently generated using Jekyll and hosted in an AWS S3 bucket. As I now intend to keep a fairly regular posting schedule I wanted to streamline my process from a local draft to a published post. One of the parts of this process that was manual was uploading newly generated site files to S3. I wanted to push the new and modified files with a single terminal command.
Since this was a fairly basic program to write I thought I would use it as an opportunity to try out a new programming language. After considering a few options I decided to go with Rust.
Rust is being developed as a research project by Mozilla, with the eventual goal of Rust becoming one of the primary languages used in their projects and replacing C++ in their codebases. It is a systems language with it’s main goals including memory safety and speed. In the case of memory safety, established systems languages such as C and C++ leave memory management to the programmer, which can lead to very serious bugs and vulnerabilities. However this same ability to do potentially unsafe things with memory can also be a very useful tool for certain tasks, and so Rust provides the ability to do unsafe things if that is specifically requested for in parts of a Rust program.
Rust is designed to target performance sensitive applications such as web browsers and their underlying engines with Mozilla’s Servo project being the main driving force behind the language. Due to it being a fast systems language it’s uses could also include anything from embedded system software to writing games/game engines.
Another difference between Rust and existing systems languages is that it’s library ecosystem (accessed using cross platform tooling) is centralised to make package discovery and installation easier.
Using Rust to create my utility
Since Rust is a new language, resources for learning are limited compared to more established languages. For the most part I kept to reading either the official documentation (aka The Rust Programming Language book), and later the documentation for the “crates” (Rust’s term for libraries) that I was using. After reading through the basics of the language from the first few chapters of the book I decided to start writing the program and learn anything I had not yet read as I went.
It did not take too long to get the basics for what I needed running. For the most part Rust’s language features seemed to make sense once you got into the mindset it has. One slight surprise was when the compiler generated warnings about code style, such as warnings for not using snake case for variable/function names. Having these kind of rules in a compiler was a bit unexpected but I decided to go with their default style to try it out, rather than immediately finding a way to turn those warnings off and ignore it.
When it came specifically to the AWS S3 access, Amazon has yet to officially support Rust with an SDK. However I found a community library called Rusoto that provides a Rust AWS SDK including S3 access.
I completed the utility with the features I needed and included some extra polish such as adding some colours in the terminal output (the green “New” and “Modified” in the screenshot below for example).
The source for s3-file-upload is hosted on GitHub: https://github.com/stevenjt/s3-file-upload
Using Rust for future projects?
After using Rust briefly for this small utility I can see myself continuing to look further into the language and have some ideas for larger projects that could be better suited to it. Trying to write something in Rust that is targeting the web via WebAssembly and Emscripten could be interesting too (with support for this in the experimental stage).