@@ -854,55 +854,55 @@ impl<T> Option<T> {
854
854
// Entry-like operations to insert if None and return a reference
855
855
/////////////////////////////////////////////////////////////////////////
856
856
857
- /// Inserts the default value into the option if it is [`None`], then
857
+ /// Inserts ` value` into the option if it is [`None`], then
858
858
/// returns a mutable reference to the contained value.
859
859
///
860
860
/// # Examples
861
861
///
862
862
/// ```
863
- /// #![feature(option_get_or_default)]
864
- ///
865
863
/// let mut x = None;
866
864
///
867
865
/// {
868
- /// let y: &mut u32 = x.get_or_default( );
869
- /// assert_eq!(y, &0 );
866
+ /// let y: &mut u32 = x.get_or_insert(5 );
867
+ /// assert_eq!(y, &5 );
870
868
///
871
869
/// *y = 7;
872
870
/// }
873
871
///
874
872
/// assert_eq!(x, Some(7));
875
873
/// ```
876
874
#[ inline]
877
- #[ unstable( feature = "option_get_or_default" , issue = "82901" ) ]
878
- pub fn get_or_default ( & mut self ) -> & mut T
879
- where
880
- T : Default ,
881
- {
882
- self . get_or_insert_with ( Default :: default)
875
+ #[ stable( feature = "option_entry" , since = "1.20.0" ) ]
876
+ pub fn get_or_insert ( & mut self , value : T ) -> & mut T {
877
+ self . get_or_insert_with ( || value)
883
878
}
884
879
885
- /// Inserts ` value` into the option if it is [`None`], then
880
+ /// Inserts the default value into the option if it is [`None`], then
886
881
/// returns a mutable reference to the contained value.
887
882
///
888
883
/// # Examples
889
884
///
890
885
/// ```
886
+ /// #![feature(option_get_or_insert_default)]
887
+ ///
891
888
/// let mut x = None;
892
889
///
893
890
/// {
894
- /// let y: &mut u32 = x.get_or_insert(5 );
895
- /// assert_eq!(y, &5 );
891
+ /// let y: &mut u32 = x.get_or_insert_default( );
892
+ /// assert_eq!(y, &0 );
896
893
///
897
894
/// *y = 7;
898
895
/// }
899
896
///
900
897
/// assert_eq!(x, Some(7));
901
898
/// ```
902
899
#[ inline]
903
- #[ stable( feature = "option_entry" , since = "1.20.0" ) ]
904
- pub fn get_or_insert ( & mut self , value : T ) -> & mut T {
905
- self . get_or_insert_with ( || value)
900
+ #[ unstable( feature = "option_get_or_insert_default" , issue = "82901" ) ]
901
+ pub fn get_or_insert_default ( & mut self ) -> & mut T
902
+ where
903
+ T : Default ,
904
+ {
905
+ self . get_or_insert_with ( Default :: default)
906
906
}
907
907
908
908
/// Inserts a value computed from `f` into the option if it is [`None`],
0 commit comments