We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 263d868 + 5adef6c commit d5bc784Copy full SHA for d5bc784
library/std/src/alloc.rs
@@ -296,6 +296,20 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
296
/// about the allocation that failed.
297
///
298
/// The allocation error hook is a global resource.
299
+///
300
+/// # Examples
301
302
+/// ```
303
+/// #![feature(alloc_error_hook)]
304
305
+/// use std::alloc::{Layout, set_alloc_error_hook};
306
307
+/// fn custom_alloc_error_hook(layout: Layout) {
308
+/// panic!("memory allocation of {} bytes failed", layout.size());
309
+/// }
310
311
+/// set_alloc_error_hook(custom_alloc_error_hook);
312
313
#[unstable(feature = "alloc_error_hook", issue = "51245")]
314
pub fn set_alloc_error_hook(hook: fn(Layout)) {
315
HOOK.store(hook as *mut (), Ordering::SeqCst);
0 commit comments