Skip to content
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

Documentation and formatting changes for option.rs. #12965

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 10 additions & 10 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<T> Option<T> {
}
}

/// Returns the contained value or a default
/// Returns the contained value or a default.
#[inline]
pub fn unwrap_or(self, def: T) -> T {
match self {
Expand All @@ -158,7 +158,7 @@ impl<T> Option<T> {
}
}

/// Returns the contained value or computes it from a closure
/// Returns the contained value or computes it from a closure.
#[inline]
pub fn unwrap_or_else(self, f: || -> T) -> T {
match self {
Expand All @@ -183,7 +183,7 @@ impl<T> Option<T> {
match self { None => def, Some(t) => f(t) }
}

/// Apply a function to the contained value or do nothing.
/// Applies a function to the contained value or does nothing.
/// Returns true if the contained value was mutated.
pub fn mutate(&mut self, f: |T| -> T) -> bool {
if self.is_some() {
Expand All @@ -192,7 +192,7 @@ impl<T> Option<T> {
} else { false }
}

/// Apply a function to the contained value or set it to a default.
/// Applies a function to the contained value or sets it to a default.
/// Returns true if the contained value was mutated, or false if set to the default.
pub fn mutate_or_set(&mut self, def: T, f: |T| -> T) -> bool {
if self.is_some() {
Expand All @@ -208,19 +208,19 @@ impl<T> Option<T> {
// Iterator constructors
/////////////////////////////////////////////////////////////////////////

/// Return an iterator over the possibly contained value
/// Returns an iterator over the possibly contained value.
#[inline]
pub fn iter<'r>(&'r self) -> Item<&'r T> {
Item{opt: self.as_ref()}
}

/// Return a mutable iterator over the possibly contained value
/// Returns a mutable iterator over the possibly contained value.
#[inline]
pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> {
Item{opt: self.as_mut()}
}

/// Return a consuming iterator over the possibly contained value
/// Returns a consuming iterator over the possibly contained value.
#[inline]
pub fn move_iter(self) -> Item<T> {
Item{opt: self}
Expand Down Expand Up @@ -264,15 +264,15 @@ impl<T> Option<T> {
pub fn or_else(self, f: || -> Option<T>) -> Option<T> {
match self {
Some(_) => self,
None => f(),
None => f()
}
}

/////////////////////////////////////////////////////////////////////////
// Misc
/////////////////////////////////////////////////////////////////////////

/// Take the value out of the option, leaving a `None` in its place.
/// Takes the value out of the option, leaving a `None` in its place.
#[inline]
pub fn take(&mut self) -> Option<T> {
mem::replace(self, None)
Expand All @@ -282,7 +282,7 @@ impl<T> Option<T> {
#[inline(always)]
pub fn filtered(self, f: |t: &T| -> bool) -> Option<T> {
match self {
Some(x) => if f(&x) {Some(x)} else {None},
Some(x) => if f(&x) { Some(x) } else { None },
None => None
}
}
Expand Down