Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
muramasa8191 committed May 30, 2022
1 parent 9879c77 commit a8fffbb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ 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 @@ -457,15 +466,7 @@ 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:
///
/// ```
/// use once_cell::unsync::OnceCell;
///
/// let mut cell: OnceCell<u32> = OnceCell::new();
/// cell.set(92).unwrap();
/// cell = OnceCell::new();
/// ```
/// interior mutability, `&mut` access permits arbitrary modification.
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 a8fffbb

Please sign in to comment.