title: How do I place a Rust module in a separate file?
body: <p>The code below is adapted from &quot;the book&quot; (rustup docs --book), and works as intended in this form - as a single .rs file.   I simply want the module to reside in a separate file.  I've read Chapter 7 of &quot;the book&quot;, &quot;Managing Growing Projects with Packages, Crates, and Modules&quot;.   I'm just not getting &quot;it&quot;.   My notion is that the &quot;main&quot; code belongs in main.rs, and the module may need to be in lib.rs, but the exact forms and placements are still a mystery.  The chapter often states to run &quot;cargo new/build whatever&quot;, but doesn't state from what directory.  Likewise, it states that src/main.rs or src/lib.rs should look like such-and-such for a particular example, but it's not clear (without a full path) if one &quot;src&quot; directory is actually in the same location as another.</p>
  <p>So, I imagine that's there more than one way to do this, but I'll be happy with a relatively simple answer.  In this instance, I only care that the module is accessible from the main() function seen below.</p>
  <pre><code>mod guess_mod {
      
      pub struct Guess {
          value: i32,
      }
  
      impl Guess {
          pub fn new(value: i32) -&gt; Guess {
              if value &lt; 1 || value &gt; 100 {
                  panic!(&quot;Guess value must be between 1 and 100, got {}.&quot;, value);
              }
              Guess{value}
          } 
          pub fn value(&amp;self) -&gt; i32 {
              self.value
          }
      }
  }
  
  
  use guess_mod::Guess;
  
  
  fn print_guess_value(guess: Guess) {
          println!(&quot;The value of the guess is {} &quot;, guess.value());
  }
  
  
  fn main() {
      let g = Guess::new(18);
      print_guess_value(g);
  }
  </code></pre>