Picking up rust by writing a QR code generator

I wanted to pick up rust again after having used it many years ago. After around 5 years or so I didn’t really know where to start?

Approaches to picking up a language

When learning, or as in this case re-learning, a programming language there are different approaches. For example:

I’ve read a lot of programming books and in general it’s a very good tool to learn new things. For rust you could for example read The Rust Programmaing Language, which is a pretty good introduction.

During my university time I did a little competitive programming, so you’d think I’d love the idea of solving programming puzzles. For example via Advent of Code, Project Euler or doing katas. But truth be told—I’m not that into such puzzles. I prefer making “real” projects that does something useful for me.

Following a tutorial, like the excellent writing an OS in Rust, can be amazingly useful. Both for learning a language but mostly for learning about a specific domain—like learning about operating systems.

Personally though after programming for several years, and having used so many languages, I prefer to just pick up a language and try to create something in it.

A QR code generator

By chance I found a thorough QR code tutorial and it got me thinking, is it a good starter project?

Seems pretty good! So I made one.

This is how you can produce a QR code in a string representation:

Or generate an svg:

There’s also a simple cli for the above tasks:

> cargo run --features cli -- "HELLO WORLD"




        ██████████████        ██    ██████████████        
        ██          ██  ████    ██  ██          ██        
        ██  ██████  ██    ██  ████  ██  ██████  ██        
        ██  ██████  ██  ██████████  ██  ██████  ██        
        ██  ██████  ██  ████  ██    ██  ██████  ██        
        ██          ██    ██    ██  ██          ██        
        ██████████████  ██  ██  ██  ██████████████        
                        ████  ████                        
          ██  ████████  ████    ██████  ████  ██          
        ██  ████████  ██        ████████  ██████          
            ██  ██  ████      ██    ████                  
        ██  ████  ██      ██  ████      ████              
        ████  ████████████████  ██████  ██████████        
                        ██      ██    ██  ██              
        ██████████████    ████    ████    ████████        
        ██          ██  ██  ██    ██    ██  ██████        
        ██  ██████  ██  ████  ██    ██      ██████        
        ██  ██████  ██  ██  ██████      ██  ██            
        ██  ██████  ██    ██        ██        ████        
        ██          ██  ██████    ██████    ████          
        ██████████████    ██  ██              ██          



You can customize the svg output there as well:

> cargo run --features cli -- "HELLO WORLD" -t svg --bg '#e5bde3' \
    --fg '#700' --width 200 > hello_world.svg

The documentation and overall code quality should be fairly good but as this was just a learning project I don’t plan on extending it with new features.