Comment dois-je faire une importation de base/include d'une fonction d'un module à un autre dans la Rouille 2015?

Je ne trouve pas comment inclure (ou d'importation, injecter, ou quelque autre mot) d'une fonction à partir d'un fichier (module) à l'autre.

Je démarre un nouveau projet avec

$ cd ~/projects
$ cargo new proj --bin
$ cd proj
$ tree
.
|
-- Cargo.toml
-- src
   |
   -- main.rs

- Je modifier main.rs et créer un nouveau fichier a.rs (à l'intérieur de la src dir), avec le code suivant:

principal.rs

fn main() {
    println!("{}", a::foo());
}

un.rs

pub fn foo() -> i32 { 42 }

J'ai exécuter le projet avec cargo run et obtenez l'erreur:

error[E0433]: failed to resolve: use of undeclared type or module `a`
 --> src/main.rs:2:20
  |
2 |     println!("{}", a::foo());
  |                    ^ use of undeclared type or module `a`

Il semble que j'ai besoin d'importer le a en quelque sorte. J'ai essayé d'ajouter la suite d'une première ligne de main.rs

  • use a;

    error[E0432]: unresolved import `a`
     --> src/main.rs:1:5
      |
    1 | use a;
      |     ^ no `a` in the root
  • use a::*;

    error[E0432]: unresolved import `a`
     --> src/main.rs:1:5
      |
    1 | use a::*;
      |     ^ maybe a missing `extern crate a;`?
    
    error[E0433]: failed to resolve: use of undeclared type or module `a`
     --> src/main.rs:4:20
      |
    4 |     println!("{}", a::foo());
      |                    ^ use of undeclared type or module `a`
  • use a::foo;

    error[E0432]: unresolved import `a`
     --> src/main.rs:1:5
      |
    1 | use a::foo;
      |     ^ maybe a missing `extern crate a;`?
    
    error[E0433]: failed to resolve: use of undeclared type or module `a`
     --> src/main.rs:4:20
      |
    4 |     println!("{}", a::foo());
      |                    ^ use of undeclared type or module `a`
  • extern crate a; use a::foo;

    error[E0463]: can't find crate for `a`
     --> src/main.rs:1:1
      |
    1 | extern crate a;
      | ^^^^^^^^^^^^^^^ can't find crate
  • extern crate proj; use proj::a::foo;

    error[E0463]: can't find crate for `proj`
     --> src/main.rs:1:1
      |
    1 | extern crate proj;
      | ^^^^^^^^^^^^^^^^^^ can't find crate

J'ai lu le guide mais ne peut toujours pas comprendre comment le faire importations.

InformationsquelleAutor vil | 2014-10-06