Skip to content

Commit ea106f7

Browse files
committed
core: correct the casing of result::{Ok,Err} in the docs
1 parent 796b337 commit ea106f7

File tree

2 files changed

+58
-60
lines changed

2 files changed

+58
-60
lines changed

src/libstd/result.rs

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ impl<T, E> Result<T, E> {
3535
/**
3636
* Convert to the `either` type
3737
*
38-
* `ok` result variants are converted to `either::right` variants, `err`
39-
* result variants are converted to `either::left`.
38+
* `Ok` result variants are converted to `either::Right` variants, `Err`
39+
* result variants are converted to `either::Left`.
4040
*/
4141
#[inline]
4242
pub fn to_either(self)-> Either<E, T>{
@@ -56,13 +56,12 @@ impl<T, E> Result<T, E> {
5656
#[inline]
5757
pub fn get_ref<'a>(&'a self) -> &'a T {
5858
match *self {
59-
Ok(ref t) => t,
60-
Err(ref the_err) =>
61-
fail!("get_ref called on error result: %?", *the_err)
59+
Ok(ref t) => t,
60+
Err(ref e) => fail!("get_ref called on `Err` result: %?", *e),
6261
}
6362
}
6463

65-
/// Returns true if the result is `ok`
64+
/// Returns true if the result is `Ok`
6665
#[inline]
6766
pub fn is_ok(&self) -> bool {
6867
match *self {
@@ -71,7 +70,7 @@ impl<T, E> Result<T, E> {
7170
}
7271
}
7372

74-
/// Returns true if the result is `err`
73+
/// Returns true if the result is `Err`
7574
#[inline]
7675
pub fn is_err(&self) -> bool {
7776
!self.is_ok()
@@ -80,99 +79,99 @@ impl<T, E> Result<T, E> {
8079
/**
8180
* Call a method based on a previous result
8281
*
83-
* If `*self` is `ok` then the value is extracted and passed to `op` whereupon
84-
* `op`s result is returned. if `*self` is `err` then it is immediately
85-
* returned. This function can be used to compose the results of two
86-
* functions.
82+
* If `self` is `Ok` then the value is extracted and passed to `op`
83+
* whereupon `op`s result is returned. if `self` is `Err` then it is
84+
* immediately returned. This function can be used to compose the results
85+
* of two functions.
8786
*
8887
* Example:
8988
*
90-
* read_file(file).iter() { |buf|
89+
* do read_file(file).iter |buf| {
9190
* print_buf(buf)
9291
* }
9392
*/
9493
#[inline]
9594
pub fn iter(&self, f: &fn(&T)) {
9695
match *self {
9796
Ok(ref t) => f(t),
98-
Err(_) => ()
97+
Err(_) => (),
9998
}
10099
}
101100

102101
/**
103102
* Call a method based on a previous result
104103
*
105-
* If `*self` is `err` then the value is extracted and passed to `op` whereupon
106-
* `op`s result is returned. if `*self` is `ok` then it is immediately returned.
107-
* This function can be used to pass through a successful result while
108-
* handling an error.
104+
* If `self` is `Err` then the value is extracted and passed to `op`
105+
* whereupon `op`s result is returned. if `self` is `Ok` then it is
106+
* immediately returned. This function can be used to pass through a
107+
* successful result while handling an error.
109108
*/
110109
#[inline]
111110
pub fn iter_err(&self, f: &fn(&E)) {
112111
match *self {
113112
Ok(_) => (),
114-
Err(ref e) => f(e)
113+
Err(ref e) => f(e),
115114
}
116115
}
117116

118-
/// Unwraps a result, assuming it is an `ok(T)`
117+
/// Unwraps a result, assuming it is an `Ok(T)`
119118
#[inline]
120119
pub fn unwrap(self) -> T {
121120
match self {
122121
Ok(t) => t,
123-
Err(_) => fail!("unwrap called on an err result")
122+
Err(_) => fail!("unwrap called on an `Err` result"),
124123
}
125124
}
126125

127-
/// Unwraps a result, assuming it is an `err(U)`
126+
/// Unwraps a result, assuming it is an `Err(U)`
128127
#[inline]
129128
pub fn unwrap_err(self) -> E {
130129
match self {
131-
Err(u) => u,
132-
Ok(_) => fail!("unwrap called on an ok result")
130+
Err(e) => e,
131+
Ok(_) => fail!("unwrap called on an `Ok` result"),
133132
}
134133
}
135134

136135
/**
137136
* Call a method based on a previous result
138137
*
139-
* If `self` is `ok` then the value is extracted and passed to `op` whereupon
140-
* `op`s result is returned. if `self` is `err` then it is immediately
141-
* returned. This function can be used to compose the results of two
142-
* functions.
138+
* If `self` is `Ok` then the value is extracted and passed to `op`
139+
* whereupon `op`s result is returned. if `self` is `Err` then it is
140+
* immediately returned. This function can be used to compose the results
141+
* of two functions.
143142
*
144143
* Example:
145144
*
146-
* let res = do read_file(file).chain |buf| {
147-
* ok(parse_bytes(buf))
145+
* let res = do read_file(file) |buf| {
146+
* Ok(parse_bytes(buf))
148147
* };
149148
*/
150149
#[inline]
151-
pub fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
150+
pub fn chain<U>(self, op: &fn(T) -> Result<U, E>) -> Result<U, E> {
152151
match self {
153152
Ok(t) => op(t),
154-
Err(e) => Err(e)
153+
Err(e) => Err(e),
155154
}
156155
}
157156

158157
/**
159-
* Call a method based on a previous result
160-
*
161-
* If `self` is `err` then the value is extracted and passed to `op`
162-
* whereupon `op`s result is returned. if `self` is `ok` then it is
163-
* immediately returned. This function can be used to pass through a
164-
* successful result while handling an error.
165-
*/
158+
* Call a function based on a previous result
159+
*
160+
* If `self` is `Err` then the value is extracted and passed to `op`
161+
* whereupon `op`s result is returned. if `self` is `Ok` then it is
162+
* immediately returned. This function can be used to pass through a
163+
* successful result while handling an error.
164+
*/
166165
#[inline]
167-
pub fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
166+
pub fn chain_err<F>(self, op: &fn(E) -> Result<T, F>) -> Result<T, F> {
168167
match self {
169168
Ok(t) => Ok(t),
170-
Err(v) => op(v)
169+
Err(e) => op(e),
171170
}
172171
}
173172
}
174173

175-
impl<T:Clone,E> Result<T, E> {
174+
impl<T: Clone, E> Result<T, E> {
176175
/**
177176
* Get the value out of a successful result
178177
*
@@ -183,18 +182,18 @@ impl<T:Clone,E> Result<T, E> {
183182
#[inline]
184183
pub fn get(&self) -> T {
185184
match *self {
186-
Ok(ref t) => (*t).clone(),
187-
Err(ref e) => fail!("get called on error result: %?", *e),
185+
Ok(ref t) => t.clone(),
186+
Err(ref e) => fail!("get called on `Err` result: %?", *e),
188187
}
189188
}
190189

191190
/**
192191
* Call a method based on a previous result
193192
*
194-
* If `*self` is `err` then the value is extracted and passed to `op` whereupon
195-
* `op`s result is wrapped in an `err` and returned. if `*self` is `ok` then it
196-
* is immediately returned. This function can be used to pass through a
197-
* successful result while handling an error.
193+
* If `self` is `Err` then the value is extracted and passed to `op`
194+
* whereupon `op`s result is wrapped in an `Err` and returned. if `self` is
195+
* `Ok` then it is immediately returned. This function can be used to pass
196+
* through a successful result while handling an error.
198197
*/
199198
#[inline]
200199
pub fn map_err<F:Clone>(&self, op: &fn(&E) -> F) -> Result<T,F> {
@@ -205,7 +204,7 @@ impl<T:Clone,E> Result<T, E> {
205204
}
206205
}
207206

208-
impl<T, E:Clone> Result<T, E> {
207+
impl<T, E: Clone> Result<T, E> {
209208
/**
210209
* Get the value out of an error result
211210
*
@@ -216,24 +215,24 @@ impl<T, E:Clone> Result<T, E> {
216215
#[inline]
217216
pub fn get_err(&self) -> E {
218217
match *self {
219-
Err(ref u) => (*u).clone(),
220-
Ok(_) => fail!("get_err called on ok result"),
218+
Err(ref e) => e.clone(),
219+
Ok(_) => fail!("get_err called on `Ok` result")
221220
}
222221
}
223222

224223
/**
225224
* Call a method based on a previous result
226225
*
227-
* If `res` is `ok` then the value is extracted and passed to `op` whereupon
228-
* `op`s result is wrapped in `ok` and returned. if `res` is `err` then it is
229-
* immediately returned. This function can be used to compose the results of
230-
* two functions.
226+
* If `self` is `Ok` then the value is extracted and passed to `op`
227+
* whereupon `op`s result is wrapped in `Ok` and returned. if `self` is
228+
* `Err` then it is immediately returned. This function can be used to
229+
* compose the results of two functions.
231230
*
232231
* Example:
233232
*
234-
* let res = read_file(file).map() { |buf|
233+
* let res = do read_file(file).map |buf| {
235234
* parse_bytes(buf)
236-
* });
235+
* };
237236
*/
238237
#[inline]
239238
pub fn map<U:Clone>(&self, op: &fn(&T) -> U) -> Result<U,E> {
@@ -254,8 +253,8 @@ impl<T, E:Clone> Result<T, E> {
254253
* checking for overflow:
255254
*
256255
* fn inc_conditionally(x: uint) -> result<uint,str> {
257-
* if x == uint::max_value { return err("overflow"); }
258-
* else { return ok(x+1u); }
256+
* if x == uint::max_value { return Err("overflow"); }
257+
* else { return Ok(x+1u); }
259258
* }
260259
* map(~[1u, 2u, 3u], inc_conditionally).chain {|incd|
261260
* assert!(incd == ~[2u, 3u, 4u]);
@@ -340,7 +339,6 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
340339
return Ok(());
341340
}
342341

343-
344342
#[cfg(test)]
345343
mod tests {
346344
use result::{Err, Ok, Result};

src/test/run-fail/result-get-fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:get called on error result: ~"kitty"
11+
// error-pattern:get called on `Err` result: ~"kitty"
1212

1313
use std::result;
1414

0 commit comments

Comments
 (0)