title: how to return current working directory from function?
body: <p>has experience with high level programming languages. I read the Rust book and now trying to survive and understand how the &quot;things&quot; in Rust works. I would love that someone explain what the heck is - Ok(()) and how to deal with it? My goal is to return result from function in to the variable where the output:</p>
  <pre><code>    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
       Running `target/debug/rcp ./file/ aba`
  Ok(
      &quot;/home/tomand/rcp&quot;,
  )
  </code></pre>
  <p>Here is the full code:</p>
  <pre><code>use std::fs;
  use std::env;
  use serde_json;
  use regex::Regex;
  use std::path::Path;
  
  fn determinate_file_size(file: &amp;str) -&gt; u64 {
      fs::metadata(file).unwrap().len()
  }
  
  fn determinate_is_it_file_or_dirctory(arg: &amp;str) -&gt; &amp;str {
      let file = &quot;File&quot;;
      let dir = &quot;Directory&quot;;
      let re = Regex::new(r&quot;/&quot;).unwrap();
      if re.is_match(arg) {
          return dir;
      }
      return file;
  }
  
  fn collect_user_arguments() -&gt; Vec&lt;String&gt; {
      env::args().collect()
  }
  
  fn check_if_arguments_count_valid(args: &amp;Vec&lt;String&gt;) -&gt; bool {
      if args.len() == 3 {
          return true
      }
      help();
      return false
  }
  
  fn get_current_working_dir() -&gt; Result&lt;T&gt; {
      env::current_dir()
  }
  
  fn help() {
      println!(&quot;Examples:&quot;);
      println!(&quot;rcp [srcfile] [destfile]&quot;);
      println!(&quot;rcp [srcdir]/[srcfile] [destdir]/[destfile]&quot;);
  }
  
  
  fn main() {
      let WORKING_DIR = get_current_working_dir();
      let args: Vec&lt;String&gt; = collect_user_arguments();
  
      if check_if_arguments_count_valid(&amp;args) {
          let arg1 = &amp;args[1];
          let arg2 = &amp;args[2];
          println!(&quot;{:#?}&quot;, determinate_is_it_file_or_dirctory(&amp;arg1));
      }
  }
  </code></pre>
  <p>Seems the compiler tried to give me some inspiration but eventually we miscommunicate in the end:</p>
  <pre><code>error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied
     --&gt; src/main.rs:42:33
      |
  42  | fn get_current_working_dir() -&gt; Result&lt;T&gt; {
      |                                 ^^^^^^ - supplied 1 generic argument
      |                                 |
      |                                 expected 2 generic arguments
  </code></pre>
  <p>EDIT:
  I went with this approach:</p>
  <pre><code>fn get_current_working_dir() -&gt; String {
      let res = env::current_dir();
      match res {
          Ok(path) =&gt; path.into_os_string().into_string().unwrap(),
          Err(_) =&gt; &quot;FAILED&quot;.to_string()
      }
  }
  </code></pre>
  <p>It seems more practice is required to understand the <strong>Result</strong> type and how to manage it.</p>