Hi,
I’m stumbled across error that can’t understand at all, and it boggles my mind
Here is code that compiles ok:
let yaml = load_yaml!("cli.yml");
let cfg = App::from_yaml(yaml).get_matches();
let mut config_path = "/etc/telebot.conf";
if let Some(v) = cfg.value_of("config") {
config_path = v;
}
When I move my config_path declaration two lines up so I have declaration first I’m getting compilation error. Why oh why I can’t have my variables at the beginning ?
Code that doesn’t compile:
let mut config_path = "/etc/telebot.conf";
let yaml = load_yaml!("cli.yml");
let cfg = App::from_yaml(yaml).get_matches();
if let Some(v) = cfg.value_of("config") {
config_path = v;
// println!("Hura")
}
Here is cryptic error message:
<clap macros>:2:3: 3:31 error: borrowed value does not live long enough
<clap macros>:2 & :: clap :: YamlLoader :: load_from_str ( include_str ! ( $ yml ) ) . expect
^
src/main.rs:13:16: 13:37 note: in this expansion of load_yaml! (defined in <clap macros>)
src/main.rs:12:47: 175:2 note: reference must be valid for the block suffix following statement 0 at 12:46...
src/main.rs:12 let mut config_path = "/etc/telebot.conf";
^
src/main.rs:13:38: 175:2 note: ...but borrowed value is only valid for the block suffix following statement 1 at 13:37
src/main.rs:13 let yaml = load_yaml!("cli.yml");
^
src/main.rs:16:22: 16:25 error: `cfg` does not live long enough
src/main.rs:16 if let Some(v) = cfg.value_of("config") {
^~~
src/main.rs:12:47: 175:2 note: reference must be valid for the block suffix following statement 0 at 12:46...
src/main.rs:12 let mut config_path = "/etc/telebot.conf";
^
src/main.rs:14:50: 175:2 note: ...but borrowed value is only valid for the block suffix following statement 2 at 14:49
src/main.rs:14 let cfg = App::from_yaml(yaml).get_matches();
^
error: aborting due to 2 previous errors