Getting Started with Programming in Rust

Hi 👋 I’m Jesse, and this is a free guide for anyone who is curious about the Rust programming language. I’m self-taught, and this is geared toward folks like me who learn by doing. My philosophy is “move slow and make things.”

This is about the length of a weekend project. Over the next six chapters, we’ll learn about Rust while building a rudimentary Markdown compiler called TinyMD — a command-line tool that takes a Markdown file as input, converts it to HTML, and writes that HTML to another file. For example:

$ echo "# Hello, world!" > some.md
$ tinymd some.md
Compile Markdown...
Done!
$ cat some.html
<h1>Hello, world!</h1>

We cover basic data types and variables, functions, control flow, simple matching, and file I/O. Each chapter opens with a set of learning objectives and ends with a checkpoint plus a copy of all the code written up to that point. After finishing, you’ll be ready to tackle more advanced Rust topics that are purposefully omitted here — like lifetimes, structs, methods, and traits.

# Prerequisites

This guide assumes that you:

  • have Rust installed,
  • are familiar with the command line,
  • have little to no experience with Rust, and
  • have some experience with at least one other programming language.

If you don’t have Rust installed yet, head to rustup.rs and follow the instructions.

# How this guide is written

Throughout, you’ll find code snippets — blocks of code you should write in your editor — and command snippets, which are commands you run in your terminal (their lines start with $). You’ll also find expandable asides that hold relevant-but-optional detail; click to open them.

If you’d like to see what we’ll be building, check out the TinyMD repo on GitHub.

What you'll learn

  1. PART 1

    A new project

    Scaffold a new Rust project with cargo and build your first Hello, World.

    • Create a new Rust project on the command line without errors
    • Compile and build a simple “Hello, World” Rust project without errors
  2. PART 2

    Variables & functions

    Write your first functions and integer variables, and print them to the command line.

    • Create a function without errors
    • Create an integer variable without errors
    • Print an integer variable to the command line without errors
  3. PART 3

    Strings & memory

    Work with Rust strings and memory ownership; build the compiler's banner from Cargo.toml.

    • Create a string variable without errors
    • Return a string variable from a function without errors
    • Concatenate two strings without errors
    • Print a string to the command line without errors
  4. PART 4

    Compiler logic

    Parse command-line arguments, use vectors and match blocks, and pass arguments to functions.

    • Describe how a compiler works in general
    • Create a vector without errors
    • Read and parse command-line arguments without errors
    • Implement a match block without errors
    • Pass an argument to a function without errors
  5. PART 5

    Reading & writing files

    Open and read a file line by line, compile Markdown to HTML, and write the result to disk.

    • Open a file without errors
    • Read a file line-by-line without errors
    • Describe how a Markdown compiler works
    • Write to a file without errors
  6. PART 6

    Release build

    Build an optimized release version of your compiler — and where to go from here.

    • Build a release version of a project in Rust