title: How to access the function in main.rs which has been written in a file in different directory in rust in same package
body: <p>I want to call a function inside a main.rs file. I have made one directory name "library" inside the same src folder as main.rs exist.</p>
  
  <p>src/main.rs</p>
  
  <pre><code>mod library;
  
  fn main() {
     println!("{}", library::name1::name(4));
  }
  </code></pre>
  
  <p>src/library/file.rs</p>
  
  <pre><code>pub mod name1 {
      pub fn name(a: i32) -&gt; i32 {
          println!("from diff file {}", a);
          a * a
      }
  }
  </code></pre>
  
  <p>when I call this function name in main.rs, compiler throws an error:</p>
  
  <blockquote>
    <p>error[E0583]: file not found for module library</p>
  </blockquote>
  
  <p>I think I am missing something. What is the correct way to do this? Keep in mind that the library directory is just an ordinary directory not a cargo package</p>