2012-08-11 10:21:22 -07:00
|
|
|
mod argparse {
|
2013-12-09 23:16:18 -08:00
|
|
|
pub struct Flag<'a> {
|
|
|
|
name: &'a str,
|
2016-03-03 02:32:55 +00:00
|
|
|
pub desc: &'a str,
|
2015-01-08 22:02:42 +11:00
|
|
|
max_count: usize,
|
|
|
|
value: usize
|
2012-08-11 10:21:22 -07:00
|
|
|
}
|
|
|
|
|
2013-03-25 13:21:04 -07:00
|
|
|
pub fn flag<'r>(name: &'r str, desc: &'r str) -> Flag<'r> {
|
2012-08-11 10:21:22 -07:00
|
|
|
Flag { name: name, desc: desc, max_count: 1, value: 0 }
|
|
|
|
}
|
|
|
|
|
2013-12-09 23:16:18 -08:00
|
|
|
impl<'a> Flag<'a> {
|
|
|
|
pub fn set_desc(self, s: &str) -> Flag<'a> {
|
2018-12-25 08:56:47 -07:00
|
|
|
Flag { //~ ERROR explicit lifetime required in the type of `s` [E0621]
|
2012-08-11 10:21:22 -07:00
|
|
|
name: self.name,
|
2016-03-17 04:15:06 -04:00
|
|
|
desc: s,
|
2012-08-11 10:21:22 -07:00
|
|
|
max_count: self.max_count,
|
|
|
|
value: self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main () {
|
2014-05-19 23:19:56 -07:00
|
|
|
let f : argparse::Flag = argparse::flag("flag", "My flag");
|
|
|
|
let updated_flag = f.set_desc("My new flag");
|
2015-02-01 21:53:25 -05:00
|
|
|
assert_eq!(updated_flag.desc, "My new flag");
|
2012-08-11 10:21:22 -07:00
|
|
|
}
|