Thanks to visit codestin.com
Credit goes to lib.rs

#play-game #rust-compiler #type-system #rules #write #tutorial #copper #enforced #ore #furnace

bin+lib rustorio

The first game written and played entirely in Rust's type system. Not just do you play by writing Rust code, the rules of the game are enforced by the Rust compiler! If you can write the program so it compiles and doesn't panic, you win!

5 releases

Uses new Rust 2024

0.0.5 Dec 14, 2025
0.0.4 Dec 14, 2025
0.0.3 Nov 24, 2025
0.0.2 Nov 23, 2025
0.0.1 Nov 22, 2025

#100 in Games

MIT/Apache

67KB
1K SLoC

Rustorio   Latest Version Docs Discord

The first game written and played entirely in Rust's type system. Not just do you play by writing Rust code, the rules of the game are enforced by the Rust compiler! If you can write the program so it compiles and doesn't panic, you win!

A while ago I realized that with Rust's affine types and ownership, it was possible to simulate resource scarcity. Combined with the richness of the type system, I wondered if it was possible to create a game with the rules enforced entirely by the Rust compiler. Well, it looks like it is.

The actual mechanics are heavily inspired by Factorio and similar games, but you play by filling out a function, and if it compiles and doesn't panic, you've won! As an example, in the tutorial level, you start with 10 iron

fn user_main(mut tick: Tick, starting_resources: StartingResources) -> (Tick, Bundle<Copper, 1>) {
    let StartingResources { iron } = starting_resources;

You can use this to create a Furnace to turn copper ore (which you get by using mine_copper) into copper.

    let mut furnace = Furnace::build(&tick, IronSmelting, iron);

    let copper_ore = rustorio::mine_copper::<8>(&mut tick);

    furnace.add_input(&tick, copper_ore);
    tick.advance_until(|tick| furnace.cur_output(tick) > 0, 100);

Because none of these types implement Copy or Clone and because they all have hidden fields, the only way (I hope) to create them is through the use of other resources, or in the case of ore, time.

The game is pretty simple and easy right now, but I have many ideas for future features. I really enjoy figuring our how to wrangle the Rust language into doing what I want in this way, and I really hope some of you enjoy this kind of this as well. Please do give it a try and tell me what you think!

How to play

  1. Install Rust. Specifically it's important to have the entire rustup toolchain and cargo, all of which you get automatically by following the instructions in the link.
  2. Install rustorio by running cargo +nightly install rustorio.
  3. Set up a new Rustorio project by running rustorio setup <path>, where <path> is the directory you want to create the project in (defaults to '.').
  4. Under src/bin/tutorial/ you will find a tutorial save. You can start by playing that one.
  5. Playing the game consists of filling out the user_main function in the main.rs file in the save game folder created for you.
  6. Run with rustorio play <save name> (e.g. rustorio play tutorial). This will compile and run your save. If it compiles and completes without panicking, you win! It'll then tell you how many ticks it took you to win.

After the tutorial

To play other game modes, run rustorio new-game and specify a game mode. Use rustorio new-game --help to see all available game modes.

Rules

The rules are mostly enforced by the compiler. The only two (current) exceptions are:

  1. Do not remove #![forbid(unsafe_code)] at the top of the main.rs file.
  2. Do not exploit unsoundness in the compiler. Both these would allow you to bypass the rules enforced by the compiler and make the game trivial. If you find other ways to bypass the rules or to do things that feel like cheating (e.g. this issue), please file an issue! Part of my interest in this project is seeing how close we can get to rule out all possible cheating vectors using only the Rust compiler. So I'd love to hear about any ways to cheat.

Help

Documentation for the Rustorio library can be found here. A good place to start is to build a furnace and start mining and smelting iron. Alternatively, you can work backwards by looking at the recipe for points to figure out how to get them.

Dependencies

~0–2.3MB
~42K SLoC