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
|
|
|
|
2012-09-07 20:08:21 -05:00
|
|
|
use either::{Either, Left, Right};
|
2012-08-11 12:21:22 -05:00
|
|
|
|
2013-01-30 16:30:22 -06:00
|
|
|
pub struct Flag {
|
2012-09-07 16:50:47 -05:00
|
|
|
name: &str,
|
|
|
|
desc: &str,
|
|
|
|
max_count: uint,
|
2013-02-22 18:08:16 -06:00
|
|
|
value: uint
|
2012-08-11 12:21:22 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 16:30:22 -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-01-30 16:30:22 -06:00
|
|
|
pub impl Flag {
|
2012-08-11 12:21:22 -05:00
|
|
|
fn set_desc(self, s: &str) -> Flag {
|
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");
|
|
|
|
assert updated_flag.desc == "My new flag";
|
|
|
|
}
|