Wie binde ich ein Modul aus einer anderen Datei desselben Projekts ein?

Folgenddieser Ratgeber Ich habe ein Frachtprojekt erstellt

src / main.rs

fn main() {
    hello::print_hello();
}

mod hello {
    pub fn print_hello() {
        println!("Hello, world!");
    }
}

welche ich laufe mit

cargo build && cargo run

und es kompiliert ohne Fehler. Jetzt versuche ich, das Hauptmodul in zwei Teile zu teilen, kann aber nicht herausfinden, wie ein Modul aus einer anderen Datei eingefügt werden kann.

Mein Projektbaum sieht so aus

├── src
    ├── hello.rs
    └── main.rs

und der Inhalt der Dateien:

src / main.rs

use hello;

fn main() {
    hello::print_hello();
}

src / hello.rs

mod hello {
    pub fn print_hello() {
        println!("Hello, world!");
    }
}

Wenn ich es kompiliere mitcargo build Ich bekomm

modules/src/main.rs:1:5: 1:10 error: unresolved import (maybe you meant `hello::*`?)
modules/src/main.rs:1 use hello;
                                                  ^~~~~
error: aborting due to previous error
Could not compile `modules`.

Ich habe versucht, den Vorschlägen des Compilers zu folgen und main.rs in @ geänder

#![feature(globs)]

extern crate hello;

use hello::*;

fn main() {
    hello::print_hello();
}

aber das hilft noch nicht viel, jetzt bekomme ich das

modules/src/main.rs:3:1: 3:20 error: can't find crate for `hello`
modules/src/main.rs:3 extern crate hello;
                                              ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `modules`.

Gibt es ein einfaches Beispiel dafür, wie ein Modul aus dem aktuellen Projekt in die Hauptdatei des Projekts eingefügt wird?

Auch ich lasse Rust 0.13.0-nightly und cargo 0.0.1-pre-nightly laufen.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage