]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/sync/lazy_lock.rs
Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-se
[rust.git] / library / std / src / sync / lazy_lock.rs
index bf5a716fa03898dd344a31c46a89a2d643dcf226..4a15305301d69714badce18702986f90be660e18 100644 (file)
@@ -49,6 +49,7 @@ pub struct LazyLock<T, F = fn() -> T> {
 impl<T, F: FnOnce() -> T> LazyLock<T, F> {
     /// Creates a new lazy value with the given initializing
     /// function.
+    #[inline]
     #[unstable(feature = "once_cell", issue = "74465")]
     pub const fn new(f: F) -> LazyLock<T, F> {
         LazyLock { cell: OnceLock::new(), init: Cell::new(Some(f)) }
@@ -70,6 +71,7 @@ pub const fn new(f: F) -> LazyLock<T, F> {
     /// assert_eq!(LazyLock::force(&lazy), &92);
     /// assert_eq!(&*lazy, &92);
     /// ```
+    #[inline]
     #[unstable(feature = "once_cell", issue = "74465")]
     pub fn force(this: &LazyLock<T, F>) -> &T {
         this.cell.get_or_init(|| match this.init.take() {
@@ -82,6 +84,8 @@ pub fn force(this: &LazyLock<T, F>) -> &T {
 #[unstable(feature = "once_cell", issue = "74465")]
 impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
     type Target = T;
+
+    #[inline]
     fn deref(&self) -> &T {
         LazyLock::force(self)
     }
@@ -90,6 +94,7 @@ fn deref(&self) -> &T {
 #[unstable(feature = "once_cell", issue = "74465")]
 impl<T: Default> Default for LazyLock<T> {
     /// Creates a new lazy value using `Default` as the initializing function.
+    #[inline]
     fn default() -> LazyLock<T> {
         LazyLock::new(T::default)
     }