2012-08-11 10:21:22 -07:00
|
|
|
mod argparse {
|
2012-09-21 18:10:45 -07:00
|
|
|
#[legacy_exports];
|
2012-09-11 17:46:20 -07:00
|
|
|
extern mod std;
|
2012-08-11 10:21:22 -07:00
|
|
|
|
2012-09-07 18:08:21 -07:00
|
|
|
use either::{Either, Left, Right};
|
2012-08-11 10:21:22 -07:00
|
|
|
|
|
|
|
struct Flag {
|
2012-09-07 14:50:47 -07:00
|
|
|
name: &str,
|
|
|
|
desc: &str,
|
|
|
|
max_count: uint,
|
|
|
|
mut value: uint
|
2012-08-11 10:21:22 -07:00
|
|
|
}
|
|
|
|
|
2012-08-20 16:53:33 -07:00
|
|
|
fn flag(name: &r/str, desc: &r/str) -> Flag/&r {
|
2012-08-11 10:21:22 -07:00
|
|
|
Flag { name: name, desc: desc, max_count: 1, value: 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Flag {
|
|
|
|
fn set_desc(self, s: &str) -> Flag {
|
2012-08-13 15:06:13 -07:00
|
|
|
Flag { //~ ERROR cannot infer an appropriate lifetime
|
2012-08-11 10:21:22 -07:00
|
|
|
name: self.name,
|
2012-11-06 18:41:06 -08:00
|
|
|
desc: s,
|
2012-08-11 10:21:22 -07: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");
|
|
|
|
assert updated_flag.desc == "My new flag";
|
|
|
|
}
|