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