// Entry-like operations to insert a value and return a reference
/////////////////////////////////////////////////////////////////////////
- /// Inserts `value` into the option then returns a mutable reference to it.
+ /// Inserts `value` into the option, then returns a mutable reference to it.
///
/// If the option already contains a value, the old value is dropped.
///
pub fn insert(&mut self, value: T) -> &mut T {
*self = Some(value);
- match self {
- Some(v) => v,
- // SAFETY: the code above just filled the option
- None => unsafe { hint::unreachable_unchecked() },
- }
+ // SAFETY: the code above just filled the option
+ unsafe { self.as_mut().unwrap_unchecked() }
}
/// Inserts `value` into the option if it is [`None`], then
}
impl<T, U> Option<(T, U)> {
- /// Unzips an option containing a tuple of two options
+ /// Unzips an option containing a tuple of two options.
///
/// If `self` is `Some((a, b))` this method returns `(Some(a), Some(b))`.
/// Otherwise, `(None, None)` is returned.
}
impl<T: Default> Option<T> {
- /// Returns the contained [`Some`] 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
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
///
/// Leaves the original `Option` in-place, creating a new one containing a mutable reference to
- /// the inner type's `Deref::Target` type.
+ /// the inner type's [`Deref::Target`] type.
///
/// # Examples
///
#[stable(since = "1.12.0", feature = "option_from")]
impl<T> From<T> for Option<T> {
- /// Copies `val` into a new `Some`.
+ /// Moves `val` into a new [`Some`].
///
/// # Examples
///
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
/// no further elements are taken, and the [`None`][Option::None] is
- /// returned. Should no [`None`][Option::None] occur, a container with the
- /// values of each [`Option`] is returned.
+ /// returned. Should no [`None`][Option::None] occur, a container of type
+ /// `V` containing the values of each [`Option`] is returned.
///
/// # Examples
///
}
impl<T> Option<Option<T>> {
- /// Converts from `Option<Option<T>>` to `Option<T>`
+ /// Converts from `Option<Option<T>>` to `Option<T>`.
///
/// # Examples
///