Crab! Learning Rust Like a Crab!

I’m a father of two boys. One is super energetic, and another one is brand new. My wife and I both have full time jobs. As you can guess, I don’t have much time for myself. My me time begins after 10 PM everyday when everyone goes to bed, and my stamina is almost depleted at that point. Don’t get me wrong. I love this honorable job (being a father). I’m also a software engineer, and a curious one at that. I want to learn a new shiny language (I mean Rust), but how?

Why Rust?

Rust is fast, really fast, and I think knowing a system language will give me more power in solving problems in the area that other high-level languages won’t be suitable. Before I started learning Rust, I’m familiar with JVM languages like Java, Kotlin, and Scala. I can pick up some other languages like Python, Ruby, Typescript and Golang in a few days, and become productive within the same day or a few days later. I’m not boasting about this. I’m going to tell you my cheat code. My usual technique is learning by doing. Reading books is not working well for me when I’m exhausted since the book will read me soon after! So, I often go to the code examples to learn the syntax and some basic APIs. I recommend going through this when time is your very limited resource. I don’t read everything. I only look at the topic that is related to what I’m working on. When I’m learning a new language, I’ll try to adapt what I already knew in one language, and transfer it to another. This strategy always worked for me until I met Rust. On the first day I tried, I felt like the compiler hated me really much. The language just ruined my self-confidence.

Did you know?

Rust’s unofficial Mascot is an orange crab named Ferris (I thought the crab 🦀 was orange only when it was cooked, but I was wrong). Rustacean is a term for Rust programmers. The term Rustacean came before the mascot. So, the mascot might be inspired by the word Crustacean. Karen Rustad Tölva drew the mascot, and Rust is part of her name. (Credit: My own research on a very reliable source — Reddit)

Rust is hard?

After the first week of getting bashed by the compiler every other night. I came to the conclusion that the language is not hard. What? really? yes it’s not hard, but it’s just different. The hard part is that you cannot do things that you normally do in other languages. Many patterns that you have under your belt no longer work. The compiler is genius, and it does pretty good job at making you feel dumb. Good thing is that it won’t let you shoot yourself on the foot. I know there is a way around it, but it’s strict by default. Moving, borrowing, and lifetime will cost you a lot of hairs at the beginning of your Rust journey unless you’re very smart or you learn it in a more proper way than I do.

How can I learn Rust?

A crab doesn’t need to learn how to walk. They just start walking. Their bodies tell them exactly on how they can move forward. They cannot walk straight, and that’s not because they don’t want to. They just can’t. The same goes for me, I tried to read some books like many others, but those books have too many details. My limitation is low, and I never go farther than 5 pages before my sleepy brain tells me “f**k it! Let’s do that again another day”.

So, I need to go with the more rewarding approach with constant feedback loop. I need to build something, and every little success will cheer me up along the way. That will keep me awake, and I’m awake because I want more of that feeling. The goal I set shouldn’t be too big, and it should be something that is useful for my daily life.

I did exact same thing when I started learning the serverless technology when it was a shiny new technology back then. I wrote the article about that on my company’s blog. I built a local tunnel service on the AWS lambda stack. Later, I wanted to learn Go and AWS announced that their Lambda service supports Go runtime. I rewrote the service again in Go The problem was that the application I wanted to develop didn’t go well with the technologies I chose :D It’s more like a hack when you want to apply serverless to something that needs a persistent connection. Anyway, AWS API gateway now supports Web Socket. That serverless idea I had may actually no longer a bad idea after all. Anyway, this time, I want my little application to be fast and easy to use. Furthermore, it shouldn’t require a complicated setup.

Run To Me

What the heck is Run To Me? Isn’t it the Bee Gees’ song? Sorry it’s not about the song. I like the song though.

Run To Me is a super-duper-simple local tunneling application proudly created by me. It was born from my learning journey, and it is my first application written in Rust. You probably know ngrok, frp, or localtunnel. This one is the same but simpler and less superior. I know my code is crap, but it does exactly what I want. If you’re looking for something that is more robust, you should shop from this awesome list:

Check it out:

The instruction on how to build and run it is in the README.

Who will be my target audiences?

  • Anyone who is looking for ngrok alternative that can be installed on premise or cloud.
  • Easy to setup with a very minimal configuration. You should be able to run it without supplying any parameter.
  • You want to learn Rust, Actix, Lapin (AMQP), Encryption. This code is a good learning resource for an absolute beginner like myself.

I’ll continue improving the code until I’m tired of it or it is perfect for my use case. Pull request is very welcome.

I’ll write about its architecture with a few code examples in the next post. Also, I’ll write the tutorials about deploying this app to the public cloud like AWS and/or Digital Ocean if people are interested.

After a week of learning by doing, I’d like to rant about things I don’t like (which may not be true when I’m no longer a n00b). Please enlighten me if I misunderstood something.

What I don’t like about Rust?

  • Compilation is very slow.
  • The syntax is a little bit verbose (and weird) compared to other modern languages like Kotlin and Scala.
  • The standard API is very minimal. This reminds me of the NodeJS ecosystem where all little things are libraries wrote by individuals like you and me. I can give you some examples — UUID, Random, Encryption, HTTP, Async are not part of the Rust standard library.
  • Things are deprecated fast. This is pretty normal for a new language, but it’s still annoying.
  • Documentation for libraries and frameworks are lacking. Many time code examples from the master branch don’t even compile. I know that sometimes developers are not very good at keeping documentation up-to-date. Speaking from a first-hand experience.
  • The cross compile seems to be not working as expected. When things go wrong, the error message is very cryptic for non-system programmer like myself.

What do I like about Rust?

Everything except those ^



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store