Skip to content

Commit

Permalink
Fix comment of not new but get_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
muramasa8191 committed May 30, 2022
1 parent a8fffbb commit a36132d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,6 @@ pub mod unsync {

impl<T> OnceCell<T> {
/// Creates a new empty cell.
///
/// # Example
/// ```
/// use once_cell::unsync::OnceCell;
///
/// let mut cell: OnceCell<u32> = OnceCell::new();
/// cell.set(92).unwrap();
/// cell = OnceCell::new();
/// ```
pub const fn new() -> OnceCell<T> {
OnceCell { inner: UnsafeCell::new(None) }
}
Expand All @@ -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<u32> = 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()
Expand Down

0 comments on commit a36132d

Please sign in to comment.