From a36132d4513f7316576a3b45ddb768210f0825ab Mon Sep 17 00:00:00 2001 From: Masa Tamura Date: Mon, 30 May 2022 16:58:29 +0900 Subject: [PATCH] Fix comment of not new but get_mut --- src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8c5d00d..e02ecb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -434,15 +434,6 @@ pub mod unsync { impl OnceCell { /// Creates a new empty cell. - /// - /// # Example - /// ``` - /// use once_cell::unsync::OnceCell; - /// - /// let mut cell: OnceCell = OnceCell::new(); - /// cell.set(92).unwrap(); - /// cell = OnceCell::new(); - /// ``` pub const fn new() -> OnceCell { OnceCell { inner: UnsafeCell::new(None) } } @@ -466,7 +457,16 @@ pub mod unsync { /// /// This method is allowed to violate the invariant of writing to a `OnceCell` /// at most once because it requires `&mut` access to `self`. As with all - /// interior mutability, `&mut` access permits arbitrary modification. + /// interior mutability, `&mut` access permits arbitrary modification: + /// + /// ``` + /// use once_cell::unsync::OnceCell; + /// + /// let mut cell: OnceCell = OnceCell::new(); + /// cell.set(92).unwrap(); + /// *cell.get_mut().unwrap() = 93; + /// assert_eq!(cell.get(), Some(&93)); + /// ``` pub fn get_mut(&mut self) -> Option<&mut T> { // Safe because we have unique access unsafe { &mut *self.inner.get() }.as_mut()