Skip to content

convert 1 line match to 2 lines for readability #18927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ impl<T> Option<T> {
#[inline]
#[stable]
pub fn as_ref<'r>(&'r self) -> Option<&'r T> {
match *self { Some(ref x) => Some(x), None => None }
match *self {
Some(ref x) => Some(x),
None => None
}
}

/// Convert from `Option<T>` to `Option<&mut T>`
Expand All @@ -253,7 +256,10 @@ impl<T> Option<T> {
#[inline]
#[unstable = "waiting for mut conventions"]
pub fn as_mut<'r>(&'r mut self) -> Option<&'r mut T> {
match *self { Some(ref mut x) => Some(x), None => None }
match *self {
Some(ref mut x) => Some(x),
None => None
}
}

/// Convert from `Option<T>` to `&mut [T]` (without copying)
Expand Down Expand Up @@ -401,7 +407,10 @@ impl<T> Option<T> {
#[inline]
#[unstable = "waiting for unboxed closures"]
pub fn map<U>(self, f: |T| -> U) -> Option<U> {
match self { Some(x) => Some(f(x)), None => None }
match self {
Some(x) => Some(f(x)),
None => None
}
}

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

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

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