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-05-20 19:07:24 -05:00
|
|
|
extern mod extra;
|
2012-08-11 12:21:22 -05:00
|
|
|
|
2013-02-26 13:34:00 -06:00
|
|
|
pub struct Flag<'self> {
|
|
|
|
name: &'self str,
|
|
|
|
desc: &'self str,
|
2012-09-07 16:50:47 -05:00
|
|
|
max_count: uint,
|
2013-02-22 18:08:16 -06:00
|
|
|
value: uint
|
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-03-25 15:21:04 -05:00
|
|
|
pub impl<'self> Flag<'self> {
|
2013-02-26 13:34:00 -06:00
|
|
|
fn set_desc(self, s: &str) -> Flag<'self> {
|
2012-08-13 17:06:13 -05:00
|
|
|
Flag { //~ ERROR cannot infer an appropriate lifetime
|
2012-08-11 12:21:22 -05:00
|
|
|
name: self.name,
|
2012-11-06 20:41:06 -06:00
|
|
|
desc: s,
|
2012-08-11 12:21:22 -05:00
|
|
|
max_count: self.max_count,
|
|
|
|
value: self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main () {
|
|
|
|
let f : argparse::Flag = argparse::flag(~"flag", ~"My flag");
|
|
|
|
let updated_flag = f.set_desc(~"My new flag");
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(updated_flag.desc, "My new flag");
|
2012-08-11 12:21:22 -05:00
|
|
|
}
|