title: How do I do a basic import/include of a function from one module to another in Rust 2015?
body: <p>I can't find how to include (or import, inject, or some other word) a function from one file (module) to another.</p>
  
  <p>I start a new project with</p>
  
  <pre class="lang-none prettyprint-override"><code>$ cd ~/projects
  $ cargo new proj --bin
  $ cd proj
  $ tree
  .
  |
  -- Cargo.toml
  -- src
     |
     -- main.rs
  </code></pre>
  
  <p>I modify <code>main.rs</code> and create a new file <code>a.rs</code> (inside the <code>src</code> dir) with the following code:</p>
  
  <p><strong>main.rs</strong></p>
  
  <pre><code>fn main() {
      println!("{}", a::foo());
  }
  </code></pre>
  
  <p><strong>a.rs</strong></p>
  
  <pre><code>pub fn foo() -&gt; i32 { 42 }
  </code></pre>
  
  <p>I run the project with <code>cargo run</code> and get the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0433]: failed to resolve: use of undeclared type or module `a`
   --&gt; src/main.rs:2:20
    |
  2 |     println!("{}", a::foo());
    |                    ^ use of undeclared type or module `a`
  </code></pre>
  
  <p>It seems that I need to import the <code>a</code> somehow. I tried to add following things as a first line to <code>main.rs</code> </p>
  
  <ul>
  <li><p><code>use a;</code> </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0432]: unresolved import `a`
   --&gt; src/main.rs:1:5
    |
  1 | use a;
    |     ^ no `a` in the root
  </code></pre></li>
  <li><p><code>use a::*;</code></p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0432]: unresolved import `a`
   --&gt; 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`
   --&gt; src/main.rs:4:20
    |
  4 |     println!("{}", a::foo());
    |                    ^ use of undeclared type or module `a`
  </code></pre></li>
  <li><p><code>use a::foo;</code></p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0432]: unresolved import `a`
   --&gt; 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`
   --&gt; src/main.rs:4:20
    |
  4 |     println!("{}", a::foo());
    |                    ^ use of undeclared type or module `a`
  </code></pre></li>
  <li><p><code>extern crate a; use a::foo;</code> </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0463]: can't find crate for `a`
   --&gt; src/main.rs:1:1
    |
  1 | extern crate a;
    | ^^^^^^^^^^^^^^^ can't find crate
  </code></pre></li>
  <li><p><code>extern crate proj; use proj::a::foo;</code> </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0463]: can't find crate for `proj`
   --&gt; src/main.rs:1:1
    |
  1 | extern crate proj;
    | ^^^^^^^^^^^^^^^^^^ can't find crate
  </code></pre></li>
  </ul>
  
  <p>I have read <a href="https://doc.rust-lang.org/0.12.0/guide.html#crates-and-modules" rel="noreferrer">the guide</a> but still cannot figure out how to do imports.</p>