@@ -169,13 +169,15 @@ impl Once {
169
169
/// [`call_once_force()`] will be no-ops.
170
170
///
171
171
/// 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 .
173
173
///
174
174
/// [`call_once()`]: Once::call_once
175
175
/// [`call_once_force()`]: Once::call_once_force
176
176
///
177
177
/// # Examples
178
178
///
179
+ /// Poison a [`Once`] by panicking in a `call_once` closure:
180
+ ///
179
181
/// ```
180
182
/// use std::sync::Once;
181
183
/// use std::thread;
@@ -202,6 +204,20 @@ impl Once {
202
204
/// // once any success happens, we stop propagating the poison
203
205
/// INIT.call_once(|| {});
204
206
/// ```
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
+ /// ```
205
221
#[ inline]
206
222
#[ stable( feature = "once_poison" , since = "1.51.0" ) ]
207
223
pub fn call_once_force < F > ( & self , f : F )
@@ -375,9 +391,9 @@ impl OnceState {
375
391
}
376
392
377
393
/// 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" ) ]
379
395
#[ inline]
380
- pub ( crate ) fn poison ( & self ) {
396
+ pub fn poison ( & self ) {
381
397
self . inner . poison ( ) ;
382
398
}
383
399
}
0 commit comments