2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-08-11 12:21:22 -05:00
|
|
|
mod argparse {
|
2013-12-10 01:16:18 -06:00
|
|
|
pub struct Flag<'a> {
|
|
|
|
name: &'a str,
|
2016-03-02 20:32:55 -06:00
|
|
|
pub desc: &'a str,
|
2015-01-08 05:02:42 -06:00
|
|
|
max_count: usize,
|
|
|
|
value: usize
|
2012-08-11 12:21:22 -05:00
|
|
|
}
|
|
|
|
|
2013-03-25 15:21:04 -05:00
|
|
|
pub fn flag<'r>(name: &'r str, desc: &'r str) -> Flag<'r> {
|
2012-08-11 12:21:22 -05:00
|
|
|
Flag { name: name, desc: desc, max_count: 1, value: 0 }
|
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a> Flag<'a> {
|
|
|
|
pub fn set_desc(self, s: &str) -> Flag<'a> {
|
2016-03-17 03:15:06 -05:00
|
|
|
Flag { //~ ERROR cannot infer
|
2012-08-11 12:21:22 -05:00
|
|
|
name: self.name,
|
2016-03-17 03:15:06 -05:00
|
|
|
desc: s,
|
2012-08-11 12:21:22 -05:00
|
|
|
max_count: self.max_count,
|
|
|
|
value: self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main () {
|
2014-05-20 01:19:56 -05:00
|
|
|
let f : argparse::Flag = argparse::flag("flag", "My flag");
|
|
|
|
let updated_flag = f.set_desc("My new flag");
|
2015-02-01 20:53:25 -06:00
|
|
|
assert_eq!(updated_flag.desc, "My new flag");
|
2012-08-11 12:21:22 -05:00
|
|
|
}
|