File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,20 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
296296/// about the allocation that failed.
297297///
298298/// 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+ /// ```
299313#[ unstable( feature = "alloc_error_hook" , issue = "51245" ) ]
300314pub fn set_alloc_error_hook ( hook : fn ( Layout ) ) {
301315 HOOK . store ( hook as * mut ( ) , Ordering :: SeqCst ) ;
You can’t perform that action at this time.
0 commit comments