2012-12-11 01:32:48 +00: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 17:21:22 +00:00
|
|
|
mod argparse {
|
2013-12-10 07:16:18 +00:00
|
|
|
pub struct Flag<'a> {
|
|
|
|
name: &'a str,
|
|
|
|
desc: &'a str,
|
2012-09-07 21:50:47 +00:00
|
|
|
max_count: uint,
|
2013-02-23 00:08:16 +00:00
|
|
|
value: uint
|
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> {
|
2014-02-10 12:44:03 +00:00
|
|
|
Flag { //~ ERROR cannot infer
|
2012-08-11 17:21:22 +00:00
|
|
|
name: self.name,
|
2012-11-07 02:41:06 +00:00
|
|
|
desc: s,
|
2012-08-11 17:21:22 +00:00
|
|
|
max_count: self.max_count,
|
|
|
|
value: self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main () {
|
2014-04-16 01:17:48 +00:00
|
|
|
let f : argparse::Flag = argparse::flag("flag".to_owned(), "My flag".to_owned());
|
|
|
|
let updated_flag = f.set_desc("My new flag".to_owned());
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(updated_flag.desc, "My new flag");
|
2012-08-11 17:21:22 +00:00
|
|
|
}
|