Skip to content

Commit

Permalink
Document alternatives to static mut
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Nov 18, 2024
1 parent ddcabfe commit 15e6fc0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,9 @@ mod self_upper_keyword {}
/// in a multithreaded context. As such, all accesses to mutable `static`s
/// require an [`unsafe`] block.
///
/// When possible, it's often better to use a non-mutable `static` with an
/// interior mutable type such as [`Mutex`], [`OnceLock`], or an [atomic].
///
/// Despite their unsafety, mutable `static`s are necessary in many contexts:
/// they can be used to represent global state shared by the whole program or in
/// [`extern`] blocks to bind to variables from C libraries.
Expand All @@ -1468,7 +1471,10 @@ mod self_upper_keyword {}
/// [`extern`]: keyword.extern.html
/// [`mut`]: keyword.mut.html
/// [`unsafe`]: keyword.unsafe.html
/// [`Mutex`]: sync::Mutex
/// [`OnceLock`]: sync::OnceLock
/// [`RefCell`]: cell::RefCell
/// [atomic]: sync::atomic
/// [Reference]: ../reference/items/static-items.html
mod static_keyword {}

Expand Down

0 comments on commit 15e6fc0

Please sign in to comment.