| Crates.io | rustorio-derive |
| lib.rs | rustorio-derive |
| version | 0.1.1 |
| created_at | 2026-01-18 16:49:22.369321+00 |
| updated_at | 2026-01-18 20:48:01.895786+00 |
| description | 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! |
| homepage | |
| repository | https://github.com/albertsgarde/rustorio |
| max_upload_size | |
| id | 2052649 |
| size | 27,931 |
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, 4>) {
let StartingResources { iron, mut copper_territory } = 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 = copper_territory.hand_mine::<8>(&mut tick);
furnace.inputs(&tick).0.add(copper_ore);
tick.advance_until(|tick| furnace.outputs(tick).0.amount() >= 1, 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! I'm especially interested in hearing what makes it work or not work as a game. It's a very weird user interface, so we're kinda reinventing some parts of game design from scratch here.
rustorio by running cargo +nightly install rustorio.rustorio setup <path>, where
<path> is the directory you want to create the project in (defaults to
'.').src/bin/tutorial/ you will find a tutorial save. You can start by
playing that one.user_main function in the
main.rs file in the save game folder created for you.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.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.
The rules are mostly enforced by the compiler. The only two (current) exceptions are:
#![forbid(unsafe_code)] at the top of the main.rs file.Both these would enable 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 ingenious exploit), 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.
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.