Skip to content

Commit 967fb97

Browse files
caassGrigorenkoPV
authored andcommitted
Mark OnceState::poison as pub
1 parent 70e814b commit 967fb97

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

library/std/src/sync/once.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ impl Once {
169169
/// [`call_once_force()`] will be no-ops.
170170
///
171171
/// The closure `f` is yielded a [`OnceState`] structure which can be used
172-
/// to query the poison status of the [`Once`].
172+
/// to query the poison status of the [`Once`] or mark the [`Once`] as poisoned.
173173
///
174174
/// [`call_once()`]: Once::call_once
175175
/// [`call_once_force()`]: Once::call_once_force
176176
///
177177
/// # Examples
178178
///
179+
/// Poison a [`Once`] by panicking in a `call_once` closure:
180+
///
179181
/// ```
180182
/// use std::sync::Once;
181183
/// use std::thread;
@@ -202,6 +204,20 @@ impl Once {
202204
/// // once any success happens, we stop propagating the poison
203205
/// INIT.call_once(|| {});
204206
/// ```
207+
///
208+
/// Poison a [`Once`] by explicitly calling [`OnceState::poison`]:
209+
///
210+
/// ```
211+
/// #![feature(once_state_poison_pub)]
212+
///
213+
/// use std::sync::Once;
214+
///
215+
/// static INIT: Once = Once::new();
216+
///
217+
/// // poison the once without panicking
218+
/// INIT.call_once_force(|p| p.poison());
219+
/// INIT.call_once_force(|p| assert!(p.is_poisoned()));
220+
/// ```
205221
#[inline]
206222
#[stable(feature = "once_poison", since = "1.51.0")]
207223
pub fn call_once_force<F>(&self, f: F)
@@ -375,9 +391,9 @@ impl OnceState {
375391
}
376392

377393
/// Poison the associated [`Once`] without explicitly panicking.
378-
// NOTE: This is currently only exposed for `OnceLock`.
394+
#[unstable(feature = "once_state_poison_pub", issue = "130327")]
379395
#[inline]
380-
pub(crate) fn poison(&self) {
396+
pub fn poison(&self) {
381397
self.inner.poison();
382398
}
383399
}

0 commit comments

Comments
 (0)