@@ -61,8 +61,9 @@ pub struct OnceLock<T> {
6161
6262impl < T > OnceLock < T > {
6363 /// Creates a new empty cell.
64- #[ unstable ( feature = "once_cell" , issue = "74465" ) ]
64+ #[ inline ]
6565 #[ must_use]
66+ #[ unstable( feature = "once_cell" , issue = "74465" ) ]
6667 pub const fn new ( ) -> OnceLock < T > {
6768 OnceLock {
6869 once : Once :: new ( ) ,
@@ -75,6 +76,7 @@ impl<T> OnceLock<T> {
7576 ///
7677 /// Returns `None` if the cell is empty, or being initialized. This
7778 /// method never blocks.
79+ #[ inline]
7880 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
7981 pub fn get ( & self ) -> Option < & T > {
8082 if self . is_initialized ( ) {
@@ -88,6 +90,7 @@ impl<T> OnceLock<T> {
8890 /// Gets the mutable reference to the underlying value.
8991 ///
9092 /// Returns `None` if the cell is empty. This method never blocks.
93+ #[ inline]
9194 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
9295 pub fn get_mut ( & mut self ) -> Option < & mut T > {
9396 if self . is_initialized ( ) {
@@ -125,6 +128,7 @@ impl<T> OnceLock<T> {
125128 /// assert_eq!(CELL.get(), Some(&92));
126129 /// }
127130 /// ```
131+ #[ inline]
128132 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
129133 pub fn set ( & self , value : T ) -> Result < ( ) , T > {
130134 let mut value = Some ( value) ;
@@ -164,6 +168,7 @@ impl<T> OnceLock<T> {
164168 /// let value = cell.get_or_init(|| unreachable!());
165169 /// assert_eq!(value, &92);
166170 /// ```
171+ #[ inline]
167172 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
168173 pub fn get_or_init < F > ( & self , f : F ) -> & T
169174 where
@@ -203,6 +208,7 @@ impl<T> OnceLock<T> {
203208 /// assert_eq!(value, Ok(&92));
204209 /// assert_eq!(cell.get(), Some(&92))
205210 /// ```
211+ #[ inline]
206212 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
207213 pub fn get_or_try_init < F , E > ( & self , f : F ) -> Result < & T , E >
208214 where
@@ -241,6 +247,7 @@ impl<T> OnceLock<T> {
241247 /// cell.set("hello".to_string()).unwrap();
242248 /// assert_eq!(cell.into_inner(), Some("hello".to_string()));
243249 /// ```
250+ #[ inline]
244251 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
245252 pub fn into_inner ( mut self ) -> Option < T > {
246253 self . take ( )
@@ -267,6 +274,7 @@ impl<T> OnceLock<T> {
267274 /// assert_eq!(cell.take(), Some("hello".to_string()));
268275 /// assert_eq!(cell.get(), None);
269276 /// ```
277+ #[ inline]
270278 #[ unstable( feature = "once_cell" , issue = "74465" ) ]
271279 pub fn take ( & mut self ) -> Option < T > {
272280 if self . is_initialized ( ) {
@@ -315,6 +323,7 @@ impl<T> OnceLock<T> {
315323 /// # Safety
316324 ///
317325 /// The value must be initialized
326+ #[ inline]
318327 unsafe fn get_unchecked ( & self ) -> & T {
319328 debug_assert ! ( self . is_initialized( ) ) ;
320329 ( & * self . value . get ( ) ) . assume_init_ref ( )
@@ -323,6 +332,7 @@ impl<T> OnceLock<T> {
323332 /// # Safety
324333 ///
325334 /// The value must be initialized
335+ #[ inline]
326336 unsafe fn get_unchecked_mut ( & mut self ) -> & mut T {
327337 debug_assert ! ( self . is_initialized( ) ) ;
328338 ( & mut * self . value . get ( ) ) . assume_init_mut ( )
@@ -360,6 +370,7 @@ impl<T> const Default for OnceLock<T> {
360370 /// assert_eq!(OnceLock::<()>::new(), OnceLock::default());
361371 /// }
362372 /// ```
373+ #[ inline]
363374 fn default ( ) -> OnceLock < T > {
364375 OnceLock :: new ( )
365376 }
@@ -377,6 +388,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
377388
378389#[ unstable( feature = "once_cell" , issue = "74465" ) ]
379390impl < T : Clone > Clone for OnceLock < T > {
391+ #[ inline]
380392 fn clone ( & self ) -> OnceLock < T > {
381393 let cell = Self :: new ( ) ;
382394 if let Some ( value) = self . get ( ) {
@@ -408,6 +420,7 @@ impl<T> From<T> for OnceLock<T> {
408420 /// Ok(())
409421 /// # }
410422 /// ```
423+ #[ inline]
411424 fn from ( value : T ) -> Self {
412425 let cell = Self :: new ( ) ;
413426 match cell. set ( value) {
@@ -419,6 +432,7 @@ impl<T> From<T> for OnceLock<T> {
419432
420433#[ unstable( feature = "once_cell" , issue = "74465" ) ]
421434impl < T : PartialEq > PartialEq for OnceLock < T > {
435+ #[ inline]
422436 fn eq ( & self , other : & OnceLock < T > ) -> bool {
423437 self . get ( ) == other. get ( )
424438 }
@@ -429,6 +443,7 @@ impl<T: Eq> Eq for OnceLock<T> {}
429443
430444#[ unstable( feature = "once_cell" , issue = "74465" ) ]
431445unsafe impl < #[ may_dangle] T > Drop for OnceLock < T > {
446+ #[ inline]
432447 fn drop ( & mut self ) {
433448 if self . is_initialized ( ) {
434449 // SAFETY: The cell is initialized and being dropped, so it can't
0 commit comments