Skip to main content

Learning Rust, A Journey Through Challenges and Fun 🚀

· 4 min read

Learning Rust for me was like revisiting my two years of experience programming embedded systems in C. There are still many concepts I don't fully understand, but that doesn't worry me because I pick them up as I work on my personal projects in Rust.

I chose a CLI project to start this journey because I felt the challenges I would face along the way would be interesting—and they were!

The Problem with Environment Variables

I work at an agency with many projects running simultaneously, usually with at least two environments (Dev and Prod, and sometimes QA too). All these projects and environments make managing and sharing environment variables complex. We've occasionally lost important variables, and sometimes we used the wrong version when syncing them to Dev (and even production 😬)!

Possible Solutions

While researching solutions that could address our issues, our intermediate solution was to use Google Docs—yes, that's right! We created a folder in Google Drive where each level would represent a project, and within each project folder, we’d have separate environments for each repository (backend, frontend, and mobile). As archaic as this solution might sound, it worked relatively well because it provided:

  • Versioning
  • Access control
  • A centralized location where everyone could update their variables

However, it was a very manual process to update both on the Drive and locally.

The Search Began

Since we use AWS for all our solutions, our first thought was to use Secrets Manager. Each developer would have a user for each project (since each client creates their own AWS accounts), and the backend would fetch the environment variable before initializing.

This solution is still on the table, and I continue to think about how it could be implemented. A major advantage is that the variables wouldn't be under our control but rather under the client's AWS account using Secrets Manager.

dotenv.org caught my attention the most. They offer access control, a web platform to simplify usage, versioning, and, most importantly, a CLI tool! My only issue is that the variables don't belong to me, and I have to pay per user to access them.

Moonenv 🌑

The idea for Moonenv came from combining the concepts of Secrets Manager and dotenv.org. I wanted environment variables to belong to me and to have a CLI-based solution.

The language for implementing it wasn't immediately clear. My first thought was Node.js since I have more experience with it and could implement it easily. But I didn't think it would be the best option (and where's the fun in that? 😅). That's when Rust came to mind! I had been reading some articles and watching videos about it, and it was time to step out of my comfort zone and dive in!

Rust provides an entire section of its documentation dedicated to creating CLI applications, with tutorials on building and distributing binaries (something I haven't done yet, but it's in the plans). It's very intuitive to implement and extremely easy to document.

Conclusion

Rust was the right choice! Along the way, I had to create a serverless application (I used GoLang) to save environment variables in an S3 Bucket, which required integrating with RestAPIs—this was also simple to implement. Error handling is another strong point: Rust forces you to handle errors in some way, making your application robust.

There are still many features to implement, with authentication and authorization being the main ones. But I know Rust will provide different and creative ways to solve these problems (it might not be easy, but that's the whole point—I want challenges)!

Check out the repository: Moonenv on GitHub 🚀