// Getting to contained values
/////////////////////////////////////////////////////////////////////////
- /// Unwraps an option, yielding the content of a [`Some`].
+ /// Returns the contained [`Some`] value, consuming the `self` value.
///
/// # Panics
///
}
}
- /// Moves the value `v` out of the `Option<T>` if it is [`Some(v)`].
+ /// Returns the contained [`Some`] value, consuming the `self` value.
///
- /// In general, because this function may panic, its use is discouraged.
+ /// Because this function may panic, its use is generally discouraged.
/// Instead, prefer to use pattern matching and handle the [`None`]
- /// case explicitly.
+ /// case explicitly, or call [`unwrap_or`], [`unwrap_or_else`], or
+ /// [`unwrap_or_default`].
+ ///
+ /// [`unwrap_or`]: #method.unwrap_or
+ /// [`unwrap_or_else`]: #method.unwrap_or_else
+ /// [`unwrap_or_default`]: #method.unwrap_or_default
///
/// # Panics
///
/// Panics if the self value equals [`None`].
///
- /// [`Some(v)`]: #variant.Some
+ /// [`Some`]: #variant.Some
/// [`None`]: #variant.None
///
/// # Examples
}
}
- /// Returns the contained value or a default.
+ /// Returns the contained [`Some`] value or a provided default.
///
/// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing
/// the result of a function call, it is recommended to use [`unwrap_or_else`],
/// which is lazily evaluated.
///
+ /// [`Some`]: #variant.Some
/// [`unwrap_or_else`]: #method.unwrap_or_else
///
/// # Examples
}
}
- /// Returns the contained value or computes it from a closure.
+ /// Returns the contained [`Some`] value or computes it from a closure.
///
/// # Examples
///
}
impl<T: fmt::Debug> Option<T> {
- /// Unwraps an option, expecting [`None`] and returning nothing.
+ /// Consumes `self` while expecting [`None`] and returning nothing.
///
/// # Panics
///
}
}
- /// Unwraps an option, expecting [`None`] and returning nothing.
+ /// Consumes `self` while expecting [`None`] and returning nothing.
///
/// # Panics
///
}
impl<T: Default> Option<T> {
- /// Returns the contained value or a default
+ /// Returns the contained [`Some`] value or a default
///
/// Consumes the `self` argument then, if [`Some`], returns the contained
/// value, otherwise if [`None`], returns the [default value] for that