Skip to content

Commit 803aacd

Browse files
committed
auto merge of #18927 : areski/rust/pr-improve-option-match-readl, r=jakub-
**match** are much more easy to read when it's not in 1 single line
2 parents 0b7b4f0 + 4aa2040 commit 803aacd

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/libcore/option.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ impl<T> Option<T> {
235235
#[inline]
236236
#[stable]
237237
pub fn as_ref<'r>(&'r self) -> Option<&'r T> {
238-
match *self { Some(ref x) => Some(x), None => None }
238+
match *self {
239+
Some(ref x) => Some(x),
240+
None => None
241+
}
239242
}
240243

241244
/// Convert from `Option<T>` to `Option<&mut T>`
@@ -253,7 +256,10 @@ impl<T> Option<T> {
253256
#[inline]
254257
#[unstable = "waiting for mut conventions"]
255258
pub fn as_mut<'r>(&'r mut self) -> Option<&'r mut T> {
256-
match *self { Some(ref mut x) => Some(x), None => None }
259+
match *self {
260+
Some(ref mut x) => Some(x),
261+
None => None
262+
}
257263
}
258264

259265
/// Convert from `Option<T>` to `&mut [T]` (without copying)
@@ -401,7 +407,10 @@ impl<T> Option<T> {
401407
#[inline]
402408
#[unstable = "waiting for unboxed closures"]
403409
pub fn map<U>(self, f: |T| -> U) -> Option<U> {
404-
match self { Some(x) => Some(f(x)), None => None }
410+
match self {
411+
Some(x) => Some(f(x)),
412+
None => None
413+
}
405414
}
406415

407416
/// Applies a function to the contained value or returns a default.
@@ -418,7 +427,10 @@ impl<T> Option<T> {
418427
#[inline]
419428
#[unstable = "waiting for unboxed closures"]
420429
pub fn map_or<U>(self, def: U, f: |T| -> U) -> U {
421-
match self { None => def, Some(t) => f(t) }
430+
match self {
431+
Some(t) => f(t),
432+
None => def
433+
}
422434
}
423435

424436
/// Applies a function to the contained value or computes a default.
@@ -437,7 +449,10 @@ impl<T> Option<T> {
437449
#[inline]
438450
#[unstable = "waiting for unboxed closures"]
439451
pub fn map_or_else<U>(self, def: || -> U, f: |T| -> U) -> U {
440-
match self { None => def(), Some(t) => f(t) }
452+
match self {
453+
Some(t) => f(t),
454+
None => def()
455+
}
441456
}
442457

443458
/// Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to

0 commit comments

Comments
 (0)