Ask coding questions

← Back to all posts
Multiple files in Rust?
DynamicSquid (4630)

How can I have multiple files in Rust compile down to a single executable?

My project structure looks like this:


My current Cargo.toml looks like this:

name = "mirror"
version = "0.0.1"
authors = ["DynamicSquid"]
edition = "2018"


name = "error"
path = "src/"

And it works fine with just the main and error files, but I can't seem to get it to work with 3 or more files.

I don't think I'm understanding Rust's Cargo system correctly.

I was thinking of using the include! macro, but I heard it was bad practice.

Any ideas?

Would you be willing to help me @Jakman?

Coder100 (16983)

first off, you don't need to change the cargo.toml file, that's nasty.

Second off, have you seen the rust tutorial?

use <rust-file>;


DynamicSquid (4630)

@Coder100 i don't think so. that's only for crates. crates can be compiled into libraries. but I can't figure out how to have multiple libraries link together