diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 7b660ed86240f2e24994b770b2d66d1cebfd4ff2..809244af12a0110968260ac816fce8c0f2d1013c 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -62,21 +62,6 @@ pub fn get_err(res: &Result) -> U { } } -/// Returns true if the result is `ok` -#[inline] -pub fn is_ok(res: &Result) -> bool { - match *res { - Ok(_) => true, - Err(_) => false - } -} - -/// Returns true if the result is `err` -#[inline] -pub fn is_err(res: &Result) -> bool { - !is_ok(res) -} - /** * Convert to the `either` type * @@ -134,27 +119,8 @@ pub fn chain_err( } } -/** - * Call a function based on a previous result - * - * If `res` is `ok` then the value is extracted and passed to `op` whereupon - * `op`s result is returned. if `res` is `err` then it is immediately - * returned. This function can be used to compose the results of two - * functions. - * - * Example: - * - * iter(read_file(file)) { |buf| - * print_buf(buf) - * } - */ -#[inline] -pub fn iter(res: &Result, f: &fn(&T)) { - match *res { - Ok(ref t) => f(t), - Err(_) => () - } -} + + /** * Call a function based on a previous result @@ -164,13 +130,7 @@ pub fn iter(res: &Result, f: &fn(&T)) { * This function can be used to pass through a successful result while * handling an error. */ -#[inline] -pub fn iter_err(res: &Result, f: &fn(&E)) { - match *res { - Ok(_) => (), - Err(ref e) => f(e) - } -} + /** * Call a function based on a previous result @@ -229,17 +189,58 @@ pub fn get_ref<'a>(&'a self) -> &'a T { } } + /// Returns true if the result is `ok` #[inline] - pub fn is_ok(&self) -> bool { is_ok(self) } + pub fn is_ok(&self) -> bool { + match *self { + Ok(_) => true, + Err(_) => false + } + } + /// Returns true if the result is `err` #[inline] - pub fn is_err(&self) -> bool { is_err(self) } + pub fn is_err(&self) -> bool { + !self.is_ok() + } + /** + * Call a function based on a previous result + * + * If `*self` is `ok` then the value is extracted and passed to `op` whereupon + * `op`s result is returned. if `res` is `err` then it is immediately + * returned. This function can be used to compose the results of two + * functions. + * + * Example: + * + * read_file(file).iter() { |buf| + * print_buf(buf) + * } + */ #[inline] - pub fn iter(&self, f: &fn(&T)) { iter(self, f) } + pub fn iter(&self, f: &fn(&T)) { + match *self { + Ok(ref t) => f(t), + Err(_) => () + } + } + /** + * Call a function based on a previous result + * + * If `*self` is `err` then the value is extracted and passed to `op` whereupon + * `op`s result is returned. if `res` is `ok` then it is immediately returned. + * This function can be used to pass through a successful result while + * handling an error. + */ #[inline] - pub fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) } + pub fn iter_err(&self, f: &fn(&E)) { + match *self { + Ok(_) => (), + Err(ref e) => f(e) + } + } #[inline] pub fn unwrap(self) -> T { unwrap(self) }