remove option.insert_with

`option.insert` covers both needs anyway, `insert_with` is
redundant.
This commit is contained in:
Canop 2020-10-01 13:24:33 +02:00
parent 9b90e1762e
commit e8df2a4269

View file

@ -581,25 +581,7 @@ impl<T> Option<T> {
#[inline]
#[unstable(feature = "option_insert", reason = "new API", issue = "none")]
pub fn insert(&mut self, v: T) -> &mut T {
self.insert_with(|| v)
}
/// Inserts a value computed from `f` into the option, then returns a
/// mutable reference to the contained value.
///
/// # Example
///
/// ```
/// #![feature(option_insert)]
///
/// let mut o = None;
/// let v = o.insert_with(|| 3);
/// assert_eq!(*v, 3);
/// ```
#[inline]
#[unstable(feature = "option_insert", reason = "new API", issue = "none")]
pub fn insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T {
*self = Some(f());
*self = Some(v);
match *self {
Some(ref mut v) => v,