@@ -32,7 +32,7 @@ pub use core::lazy::*;
32
32
/// assert!(CELL.get().is_none());
33
33
///
34
34
/// std::thread::spawn(|| {
35
- /// let value: &String = CELL.get_or_init (|| {
35
+ /// let value: &String = CELL.get_or_insert_with (|| {
36
36
/// "Hello, World!".to_string()
37
37
/// });
38
38
/// assert_eq!(value, "Hello, World!");
@@ -201,7 +201,7 @@ impl<T> SyncOnceCell<T> {
201
201
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
202
202
pub fn set ( & self , value : T ) -> Result < ( ) , T > {
203
203
let mut value = Some ( value) ;
204
- self . get_or_init ( || value. take ( ) . unwrap ( ) ) ;
204
+ self . get_or_insert_with ( || value. take ( ) . unwrap ( ) ) ;
205
205
match value {
206
206
None => Ok ( ( ) ) ,
207
207
Some ( value) => Err ( value) ,
@@ -211,7 +211,7 @@ impl<T> SyncOnceCell<T> {
211
211
/// Gets the contents of the cell, initializing it with `f` if the cell
212
212
/// was empty.
213
213
///
214
- /// Many threads may call `get_or_init ` concurrently with different
214
+ /// Many threads may call `get_or_insert_with ` concurrently with different
215
215
/// initializing functions, but it is guaranteed that only one function
216
216
/// will be executed.
217
217
///
@@ -232,17 +232,17 @@ impl<T> SyncOnceCell<T> {
232
232
/// use std::lazy::SyncOnceCell;
233
233
///
234
234
/// let cell = SyncOnceCell::new();
235
- /// let value = cell.get_or_init (|| 92);
235
+ /// let value = cell.get_or_insert_with (|| 92);
236
236
/// assert_eq!(value, &92);
237
- /// let value = cell.get_or_init (|| unreachable!());
237
+ /// let value = cell.get_or_insert_with (|| unreachable!());
238
238
/// assert_eq!(value, &92);
239
239
/// ```
240
240
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
241
- pub fn get_or_init < F > ( & self , f : F ) -> & T
241
+ pub fn get_or_insert_with < F > ( & self , f : F ) -> & T
242
242
where
243
243
F : FnOnce ( ) -> T ,
244
244
{
245
- match self . get_or_try_init ( || Ok :: < T , !> ( f ( ) ) ) {
245
+ match self . try_get_or_insert_with ( || Ok :: < T , !> ( f ( ) ) ) {
246
246
Ok ( val) => val,
247
247
}
248
248
}
@@ -268,16 +268,16 @@ impl<T> SyncOnceCell<T> {
268
268
/// use std::lazy::SyncOnceCell;
269
269
///
270
270
/// let cell = SyncOnceCell::new();
271
- /// assert_eq!(cell.get_or_try_init (|| Err(())), Err(()));
271
+ /// assert_eq!(cell.try_get_or_insert_with (|| Err(())), Err(()));
272
272
/// assert!(cell.get().is_none());
273
- /// let value = cell.get_or_try_init (|| -> Result<i32, ()> {
273
+ /// let value = cell.try_get_or_insert_with (|| -> Result<i32, ()> {
274
274
/// Ok(92)
275
275
/// });
276
276
/// assert_eq!(value, Ok(&92));
277
277
/// assert_eq!(cell.get(), Some(&92))
278
278
/// ```
279
279
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
280
- pub fn get_or_try_init < F , E > ( & self , f : F ) -> Result < & T , E >
280
+ pub fn try_get_or_insert_with < F , E > ( & self , f : F ) -> Result < & T , E >
281
281
where
282
282
F : FnOnce ( ) -> Result < T , E > ,
283
283
{
@@ -499,7 +499,7 @@ impl<T, F: FnOnce() -> T> SyncLazy<T, F> {
499
499
/// ```
500
500
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
501
501
pub fn force ( this : & SyncLazy < T , F > ) -> & T {
502
- this. cell . get_or_init ( || match this. init . take ( ) {
502
+ this. cell . get_or_insert_with ( || match this. init . take ( ) {
503
503
Some ( f) => f ( ) ,
504
504
None => panic ! ( "Lazy instance has previously been poisoned" ) ,
505
505
} )
0 commit comments