I’m getting a returns a value referencing data owned by the current function on line 17 on .unwrap_or("/tmp/"). This is the first time I try something on rust after finishing the book. I still don’t know enough to debug this.

use clap::{Arg, Command};


fn main() {
    args = parse_args();
    println!("The directory passed is: {}", args[0]);
}


fn parse_args() -> Vec<&str> {
    let matches = Command::new("Parse Torrent")
        .arg(Arg::new("dir")
            .short('f')
            .long("dir")
            .takes_value(true)
            .help("input directory of your computer, example /disk1/dir1/"))
        .get_matches();

    matches.value_of(dir).unwrap_or("/tmp/")
}

Ask specific questions about how to code something in rust

Rust Docs

General rust discussion on lemmy.ml

Create Post From:
lemmy.ml

  • 0 users online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1 user / 6 months
  • 13 subscribers
  • 1 Post
  • 0 Comments
  • Modlog