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 {
|
2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
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-02-26 13:34:00 -06:00
|
|
|
pub fn flag(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-02-26 13:34:00 -06:00
|
|
|
pub impl Flag<'self> {
|
|
|
|
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-03-06 15:58:02 -06:00
|
|
|
fail_unless!(updated_flag.desc == "My new flag");
|
2012-08-11 12:21:22 -05:00
|
|
|
}
|