Rust: Multiple-file example in guide

Created on 2 Nov 2014  路  8Comments  路  Source: rust-lang/rust

The guide, at section 14.1, mentions

We'll talk about multiple-file projects later on in the guide.

But that never happens. It almost seem to happen in section 15 Crates and Modules, but doesn't.

It would be nice to have a minimal example of a multiple-project setup with a library and an executable, e.g. with a lib crate project_a that prints "I am crate A", and an executable crate project_b with a subdir/helper.rs file that prints "I am a helper module" and a main.rs file that calls these functions in both the helper file and the other crate. At least, that was what I was missing.

The other option, for keeping the guide short, would be removing the unfulfilled promise.

Most helpful comment

I just wanted a clear and simple answer for that question and I found it on StackOverflow: http://stackoverflow.com/a/25590515/2436687

All 8 comments

Yeah, it _did_but it ended up getting removed.

I would prefer to point to the Crates Guide here.

:+1: @steveklabnik

The crates guide is now in the book, so this is fixed.

This is far from fixed, the crates guide does not explain at all how to find the way to use more than one file on your project.
It explains how to call files from one project into another project, but if if you try to have 2 files in one crate call a function from each other you will fail and the guide will not help you at all

I still can't find any resource that explains how to use multiple files. I don't want to create a library - I just want to split my code!

It works the exact same way. All Rust programs are crates.

Figured it out now. Apparently source files wrap the content implicitly into a module with the same name.

I just wanted a clear and simple answer for that question and I found it on StackOverflow: http://stackoverflow.com/a/25590515/2436687

Was this page helpful?
0 / 5 - 0 ratings