Learning Rust "from scratch"

· Gam Guerrero's blog

Yet another try to finally learn it

Table of Contents

Before #

The first time I learned about Rust was more than a decade ago, from a coworker. I got interested in it and even played around with it for a while, but I never had an actual use case for it, or rather, I just stayed in my "comfort zone" with the scripting languages I already had experience with.

This phenomenon of trying to learn and use it repeated itself a handful of times over the years. I even solved many learning exercises on different platforms, but since I've been focused on working professionally as a Python programmer, I still haven't "bitten the bullet". After all these years, I'm still not "production experienced" with it.

However, about a year ago, I discovered and started using ruff, and later uv, both tools built with Rust by Astral.sh. Experiencing firsthand the benefits of applying Rust to Python projects surprised me greatly, and it also started to "close the gap" between both languages for me.

Then, just a couple of weeks ago, I learned that they are working on a new tool: ty, a type checker that I believe will replace mypy and similar tools in the future, based on its speed alone.

Since ty is open source, I think it's finally time for me to learn and use Rust at a "production level", and since I'm also working on improving my writing skills, I'll do my best to document the process as much as possible here in this blog.

Installing ty #

First we need to get the code of course, according to their ty repository all development happens within the ruff for now.

Development of this project takes place in the Ruff repository at this time. Please open pull requests there for changes to anything in the ruff submodule (which includes all of the Rust source code).

So let's clone that one first:

1$ mkdir astral.sh
2$ cd astral.sh
3$ git@github.com:astral-sh/ruff.git
4$ cd ruff

From there, let's follow the CONTRIBUTING guide they've written for ty.

According to it, it has 2 hard prerequisites:

So let's install both:

1$ nix-shell -p git cargo uv
2$ cargo --version
3cargo 1.89.0 (c24e10642 2025-06-23)
4$ uv --version
5uv 0.8.6

They also recommend nextest to run the test suite.

$ cargo install cargo-nextest --locked

This step downloaded, compiled and build about 371 crates, I don't think it's terrible but something I must get used to, I think.

Now it's time to check ty binary without any changes to the project so far, for this I'll make a really simple Python project with a few types.

1$ uv init pydummy
2Initialized project `pydummy` at `pydummy`
 1# main.py
 2def is_even(value: int) -> bool:
 3    return value % 2 == 0
 4
 5
 6def is_odd(value: int) -> bool:
 7    return not is_even(value)
 8
 9
10def add(a: int, b: int) -> int:
11    return a + b
12
13
14def main():
15    add(1, 2)
16    is_odd(2)
17    is_even(3)
18
19
20if __name__ == "__main__":
21    main()
1$ cargo run --bin ty -- check --project ../pydummy
2    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s
3     Running `target/debug/ty check --project ../pydummy`
4WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
5Checking ------------------------------------------------------------ 1/1 files                                                                                                        All checks passed!

Success! I could build and execute ty locally for development, lastly let's see how to test suite behaves.

1$ cargo nextest run
2...
3────────────
4     Summary [  87.386s] 4972 tests run: 4972 passed, 50 skipped

This time it had to download and build 630 crates! I guess that explains why there are so many articles about supply chain attacks. The full suite ran in almost 1:30 minutes, pretty good in my opinion.

That's all for now, in the next session I'll try to figure out ty's entrypoint and continue from there.

last updated: