diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-06-22 17:32:52 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-06-22 17:32:57 -0700 |
| commit | 0cf730ed2a94718229fd2c0a3ded8fc2b18ee6ce (patch) | |
| tree | db1b9a6e490fc6ea609f9c2ed63ab9701b5891aa /src/libcore/result.rs | |
| parent | ce7b8037286731117e7709974595f1ae5bc67bce (diff) | |
| download | rust-0cf730ed2a94718229fd2c0a3ded8fc2b18ee6ce.tar.gz rust-0cf730ed2a94718229fd2c0a3ded8fc2b18ee6ce.zip | |
core: Split up result extensions by kind bounds
Diffstat (limited to 'src/libcore/result.rs')
| -rw-r--r-- | src/libcore/result.rs | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 3c6622ba69d..a5badd92610 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -180,23 +180,11 @@ fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F) } } -impl extensions<T:copy, E:copy> for result<T,E> { - fn get() -> T { get(self) } - - fn get_err() -> E { get_err(self) } - +impl extensions<T, E> for result<T, E> { fn is_success() -> bool { is_success(self) } fn is_failure() -> bool { is_failure(self) } - fn chain<U:copy>(op: fn(T) -> result<U,E>) -> result<U,E> { - chain(self, op) - } - - fn chain_err<F:copy>(op: fn(E) -> result<T,F>) -> result<T,F> { - chain_err(self, op) - } - fn iter(f: fn(T)) { alt self { ok(t) { f(t) } @@ -210,6 +198,21 @@ impl extensions<T:copy, E:copy> for result<T,E> { err(e) { f(e) } } } +} + +impl extensions<T:copy, E> for result<T, E> { + fn get() -> T { get(self) } + + fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> { + alt self { + ok(t) { ok(t) } + err(e) { err(op(e)) } + } + } +} + +impl extensions<T, E:copy> for result<T, E> { + fn get_err() -> E { get_err(self) } fn map<U:copy>(op: fn(T) -> U) -> result<U,E> { alt self { @@ -217,12 +220,15 @@ impl extensions<T:copy, E:copy> for result<T,E> { err(e) { err(e) } } } +} - fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> { - alt self { - ok(t) { ok(t) } - err(e) { err(op(e)) } - } +impl extensions<T:copy, E:copy> for result<T,E> { + fn chain<U:copy>(op: fn(T) -> result<U,E>) -> result<U,E> { + chain(self, op) + } + + fn chain_err<F:copy>(op: fn(E) -> result<T,F>) -> result<T,F> { + chain_err(self, op) } } |
