mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-30 14:52:56 +03:00
remove option.insert_with
`option.insert` covers both needs anyway, `insert_with` is redundant.
This commit is contained in:
@@ -581,25 +581,7 @@ pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
|
||||
#[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,
|
||||
|
||||
Reference in New Issue
Block a user