pub struct ChaosAllocator<A = System> { /* private fields */ }Expand description
A global allocator wrapper that can deterministically fail selected
allocation attempts during an alloc_chaos check.
Install it once in a test binary:
#[global_allocator]
static GLOBAL: alloc_chaos::ChaosAllocator = alloc_chaos::ChaosAllocator::system();The wrapper delegates to its inner allocator unless a check is active and the current allocation attempt is the selected failure target.
Implementations§
Source§impl ChaosAllocator<System>
impl ChaosAllocator<System>
Sourcepub const fn system() -> Self
pub const fn system() -> Self
Creates a wrapper around std::alloc::System.
Examples found in repository?
More examples
Source§impl<A> ChaosAllocator<A>
impl<A> ChaosAllocator<A>
Trait Implementations§
Source§impl<A> Debug for ChaosAllocator<A>
impl<A> Debug for ChaosAllocator<A>
Source§impl<A> GlobalAlloc for ChaosAllocator<A>where
A: GlobalAlloc,
impl<A> GlobalAlloc for ChaosAllocator<A>where
A: GlobalAlloc,
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given
layout. Read moreSource§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like
alloc, but also ensures that the contents
are set to zero before being returned. Read moreAuto Trait Implementations§
impl<A> Freeze for ChaosAllocator<A>where
A: Freeze,
impl<A> RefUnwindSafe for ChaosAllocator<A>where
A: RefUnwindSafe,
impl<A> Send for ChaosAllocator<A>where
A: Send,
impl<A> Sync for ChaosAllocator<A>where
A: Sync,
impl<A> Unpin for ChaosAllocator<A>where
A: Unpin,
impl<A> UnsafeUnpin for ChaosAllocator<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for ChaosAllocator<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more