【发布时间】:2021-03-05 05:02:26
【问题描述】:
我不知道如何遵循编译器的建议:consider using a let binding to create a longer lived value。
#![allow(unused)]
fn main() {
let a_dir=std::env::args().nth(2);
let dir:&str=match a_dir{
Some (ref a)=> &format!("./{}/**/*.liquid",a) as &str,
None=>{"./**/*.liquid"},
};
}
error[E0716]: temporary value dropped while borrowed
--> src/main.rs:6:23
|
5 | let dir:&str=match a_dir{
| --- borrow later stored here
6 | Some (ref a)=> &format!("./{}/**/*.liquid",a) as &str,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
|
= note: consider using a `let` binding to create a longer lived value
【问题讨论】:
标签: rust