2012-08-02 18:01:38 -05:00
|
|
|
#[link(name = "static_methods_crate",
|
|
|
|
vers = "0.1")];
|
|
|
|
|
|
|
|
#[crate_type = "lib"];
|
|
|
|
|
|
|
|
export read, readMaybe;
|
|
|
|
|
|
|
|
trait read {
|
|
|
|
static fn readMaybe(s: ~str) -> option<self>;
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl int: read {
|
2012-08-02 18:01:38 -05:00
|
|
|
static fn readMaybe(s: ~str) -> option<int> {
|
|
|
|
int::from_str(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl bool: read {
|
2012-08-02 18:01:38 -05:00
|
|
|
static fn readMaybe(s: ~str) -> option<bool> {
|
|
|
|
match s {
|
|
|
|
~"true" => some(true),
|
|
|
|
~"false" => some(false),
|
|
|
|
_ => none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn read<T: read copy>(s: ~str) -> T {
|
|
|
|
match readMaybe(s) {
|
|
|
|
some(x) => x,
|
|
|
|
_ => fail ~"read failed!"
|
|
|
|
}
|
|
|
|
}
|