pub struct Watermark<I, H> { /* private fields */ }Expand description
Watermark wrapper.
Tracks live bytes in an AtomicUsize. Fires the handler on rising
crossings of warn_pct and critical_pct, and on OOM. Falling edges
(allocations released) do NOT reset the crossing flags — once a region
reaches warn, it stays armed until manual reset (see rearm()).
Atomic variant only; non-atomic variant for single-core no_std targets
will land later. Gated by cfg(target_has_atomic = "ptr").
Implementations§
Source§impl<I: Allocator, H: WatermarkHandler> Watermark<I, H>
impl<I: Allocator, H: WatermarkHandler> Watermark<I, H>
Sourcepub fn with_thresholds(
inner: I,
handler: H,
thresholds: WatermarkThresholds,
) -> Self
pub fn with_thresholds( inner: I, handler: H, thresholds: WatermarkThresholds, ) -> Self
Wrap with explicit thresholds.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Bytes currently in use.
Trait Implementations§
Source§impl<I: Allocator, H: WatermarkHandler> Allocator for Watermark<I, H>
Available on target_has_atomic=ptr only.
impl<I: Allocator, H: WatermarkHandler> Allocator for Watermark<I, H>
Available on
target_has_atomic=ptr only.Source§fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
Allocate a block satisfying
layout. The returned slice’s length is
at least layout.size() but may be larger.Source§unsafe fn usable_size(
&self,
ptr: NonNull<u8>,
layout: NonZeroLayout,
) -> Option<usize>
unsafe fn usable_size( &self, ptr: NonNull<u8>, layout: NonZeroLayout, ) -> Option<usize>
Usable size of an existing allocation, if the allocator can report
it. Defaults to
None — implementors that track usable size
override. Read moreSource§fn capacity_bytes(&self) -> Option<usize>
fn capacity_bytes(&self) -> Option<usize>
Total bytes this allocator can issue, if bounded.
None for unbounded
allocators like System. Used by Watermark to compute thresholds.Source§fn corruption_events(&self) -> u64
fn corruption_events(&self) -> u64
Detected freelist / metadata corruption events observed by this
allocator since construction. Read more
Source§fn allocate_zeroed(
&self,
layout: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed( &self, layout: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Allocate a zero-initialized block.
Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Grow an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Shrink an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§impl<I: Allocator, H: WatermarkHandler> Deallocator for Watermark<I, H>
Available on target_has_atomic=ptr only.
impl<I: Allocator, H: WatermarkHandler> Deallocator for Watermark<I, H>
Available on
target_has_atomic=ptr only.Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout)
Release a previously allocated block. Read more
Source§impl<I: FixedRange, H: WatermarkHandler> FixedRange for Watermark<I, H>
Available on target_has_atomic=ptr only.
impl<I: FixedRange, H: WatermarkHandler> FixedRange for Watermark<I, H>
Available on
target_has_atomic=ptr only.Auto Trait Implementations§
impl<I, H> !Freeze for Watermark<I, H>
impl<I, H> RefUnwindSafe for Watermark<I, H>where
I: RefUnwindSafe,
H: RefUnwindSafe,
impl<I, H> Send for Watermark<I, H>
impl<I, H> Sync for Watermark<I, H>
impl<I, H> Unpin for Watermark<I, H>
impl<I, H> UnsafeUnpin for Watermark<I, H>where
I: UnsafeUnpin,
H: UnsafeUnpin,
impl<I, H> UnwindSafe for Watermark<I, H>where
I: UnwindSafe,
H: 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