@@ -61,8 +61,9 @@ pub struct OnceLock<T> {
61
61
62
62
impl < T > OnceLock < T > {
63
63
/// Creates a new empty cell.
64
- #[ unstable ( feature = "once_cell" , issue = "74465" ) ]
64
+ #[ inline ]
65
65
#[ must_use]
66
+ #[ unstable( feature = "once_cell" , issue = "74465" ) ]
66
67
pub const fn new ( ) -> OnceLock < T > {
67
68
OnceLock {
68
69
once : Once :: new ( ) ,
@@ -75,6 +76,7 @@ impl<T> OnceLock<T> {
75
76
///
76
77
/// Returns `None` if the cell is empty, or being initialized. This
77
78
/// method never blocks.
79
+ #[ inline]
78
80
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
79
81
pub fn get ( & self ) -> Option < & T > {
80
82
if self . is_initialized ( ) {
@@ -88,6 +90,7 @@ impl<T> OnceLock<T> {
88
90
/// Gets the mutable reference to the underlying value.
89
91
///
90
92
/// Returns `None` if the cell is empty. This method never blocks.
93
+ #[ inline]
91
94
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
92
95
pub fn get_mut ( & mut self ) -> Option < & mut T > {
93
96
if self . is_initialized ( ) {
@@ -125,6 +128,7 @@ impl<T> OnceLock<T> {
125
128
/// assert_eq!(CELL.get(), Some(&92));
126
129
/// }
127
130
/// ```
131
+ #[ inline]
128
132
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
129
133
pub fn set ( & self , value : T ) -> Result < ( ) , T > {
130
134
let mut value = Some ( value) ;
@@ -164,6 +168,7 @@ impl<T> OnceLock<T> {
164
168
/// let value = cell.get_or_init(|| unreachable!());
165
169
/// assert_eq!(value, &92);
166
170
/// ```
171
+ #[ inline]
167
172
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
168
173
pub fn get_or_init < F > ( & self , f : F ) -> & T
169
174
where
@@ -203,6 +208,7 @@ impl<T> OnceLock<T> {
203
208
/// assert_eq!(value, Ok(&92));
204
209
/// assert_eq!(cell.get(), Some(&92))
205
210
/// ```
211
+ #[ inline]
206
212
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
207
213
pub fn get_or_try_init < F , E > ( & self , f : F ) -> Result < & T , E >
208
214
where
@@ -241,6 +247,7 @@ impl<T> OnceLock<T> {
241
247
/// cell.set("hello".to_string()).unwrap();
242
248
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
243
249
/// ```
250
+ #[ inline]
244
251
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
245
252
pub fn into_inner ( mut self ) -> Option < T > {
246
253
self . take ( )
@@ -267,6 +274,7 @@ impl<T> OnceLock<T> {
267
274
/// assert_eq!(cell.take(), Some("hello".to_string()));
268
275
/// assert_eq!(cell.get(), None);
269
276
/// ```
277
+ #[ inline]
270
278
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
271
279
pub fn take ( & mut self ) -> Option < T > {
272
280
if self . is_initialized ( ) {
@@ -315,6 +323,7 @@ impl<T> OnceLock<T> {
315
323
/// # Safety
316
324
///
317
325
/// The value must be initialized
326
+ #[ inline]
318
327
unsafe fn get_unchecked ( & self ) -> & T {
319
328
debug_assert ! ( self . is_initialized( ) ) ;
320
329
( & * self . value . get ( ) ) . assume_init_ref ( )
@@ -323,6 +332,7 @@ impl<T> OnceLock<T> {
323
332
/// # Safety
324
333
///
325
334
/// The value must be initialized
335
+ #[ inline]
326
336
unsafe fn get_unchecked_mut ( & mut self ) -> & mut T {
327
337
debug_assert ! ( self . is_initialized( ) ) ;
328
338
( & mut * self . value . get ( ) ) . assume_init_mut ( )
@@ -360,6 +370,7 @@ impl<T> const Default for OnceLock<T> {
360
370
/// assert_eq!(OnceLock::<()>::new(), OnceLock::default());
361
371
/// }
362
372
/// ```
373
+ #[ inline]
363
374
fn default ( ) -> OnceLock < T > {
364
375
OnceLock :: new ( )
365
376
}
@@ -377,6 +388,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
377
388
378
389
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
379
390
impl < T : Clone > Clone for OnceLock < T > {
391
+ #[ inline]
380
392
fn clone ( & self ) -> OnceLock < T > {
381
393
let cell = Self :: new ( ) ;
382
394
if let Some ( value) = self . get ( ) {
@@ -408,6 +420,7 @@ impl<T> From<T> for OnceLock<T> {
408
420
/// Ok(())
409
421
/// # }
410
422
/// ```
423
+ #[ inline]
411
424
fn from ( value : T ) -> Self {
412
425
let cell = Self :: new ( ) ;
413
426
match cell. set ( value) {
@@ -419,6 +432,7 @@ impl<T> From<T> for OnceLock<T> {
419
432
420
433
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
421
434
impl < T : PartialEq > PartialEq for OnceLock < T > {
435
+ #[ inline]
422
436
fn eq ( & self , other : & OnceLock < T > ) -> bool {
423
437
self . get ( ) == other. get ( )
424
438
}
@@ -429,6 +443,7 @@ impl<T: Eq> Eq for OnceLock<T> {}
429
443
430
444
#[ unstable( feature = "once_cell" , issue = "74465" ) ]
431
445
unsafe impl < #[ may_dangle] T > Drop for OnceLock < T > {
446
+ #[ inline]
432
447
fn drop ( & mut self ) {
433
448
if self . is_initialized ( ) {
434
449
// SAFETY: The cell is initialized and being dropped, so it can't
0 commit comments