From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- library/core/src/cell/lazy.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'library/core/src/cell/lazy.rs') diff --git a/library/core/src/cell/lazy.rs b/library/core/src/cell/lazy.rs index b355d94ce..65d12c25c 100644 --- a/library/core/src/cell/lazy.rs +++ b/library/core/src/cell/lazy.rs @@ -35,7 +35,7 @@ pub struct LazyCell T> { init: Cell>, } -impl LazyCell { +impl T> LazyCell { /// Creates a new lazy value with the given initializing function. /// /// # Examples @@ -51,13 +51,12 @@ impl LazyCell { /// /// assert_eq!(&*lazy, "HELLO, WORLD!"); /// ``` + #[inline] #[unstable(feature = "once_cell", issue = "74465")] pub const fn new(init: F) -> LazyCell { LazyCell { cell: OnceCell::new(), init: Cell::new(Some(init)) } } -} -impl T> LazyCell { /// Forces the evaluation of this lazy value and returns a reference to /// the result. /// @@ -75,6 +74,7 @@ impl T> LazyCell { /// assert_eq!(LazyCell::force(&lazy), &92); /// assert_eq!(&*lazy, &92); /// ``` + #[inline] #[unstable(feature = "once_cell", issue = "74465")] pub fn force(this: &LazyCell) -> &T { this.cell.get_or_init(|| match this.init.take() { @@ -87,6 +87,7 @@ impl T> LazyCell { #[unstable(feature = "once_cell", issue = "74465")] impl T> Deref for LazyCell { type Target = T; + #[inline] fn deref(&self) -> &T { LazyCell::force(self) } @@ -95,6 +96,7 @@ impl T> Deref for LazyCell { #[unstable(feature = "once_cell", issue = "74465")] impl Default for LazyCell { /// Creates a new lazy value using `Default` as the initializing function. + #[inline] fn default() -> LazyCell { LazyCell::new(T::default) } -- cgit v1.2.3