pub struct MemoryGuard { /* private fields */ }Expand description
Thread-safe memory guard for monitoring and enforcing memory limits.
Implementations§
Source§impl MemoryGuard
impl MemoryGuard
Sourcepub fn new(config: MemoryGuardConfig) -> Self
pub fn new(config: MemoryGuardConfig) -> Self
Create a new memory guard with the given configuration.
Sourcepub fn default_guard() -> Self
pub fn default_guard() -> Self
Create a memory guard with default configuration.
Sourcepub fn with_limit(limit_mb: usize) -> Self
pub fn with_limit(limit_mb: usize) -> Self
Create a memory guard with specified limit.
Create an Arc-wrapped memory guard for sharing across threads.
Sourcepub fn check(&self) -> Result<(), MemoryLimitExceeded>
pub fn check(&self) -> Result<(), MemoryLimitExceeded>
Check memory limit (returns error if hard limit exceeded).
This should be called periodically during generation. It’s designed to be efficient - actual memory checks only happen at the configured interval.
Sourcepub fn check_now(&self) -> Result<(), MemoryLimitExceeded>
pub fn check_now(&self) -> Result<(), MemoryLimitExceeded>
Force an immediate memory check (bypasses interval).
Sourcepub fn stats(&self) -> MemoryStats
pub fn stats(&self) -> MemoryStats
Get current memory statistics.
Sourcepub fn current_usage_mb(&self) -> usize
pub fn current_usage_mb(&self) -> usize
Get current memory usage in MB.
Sourcepub fn peak_usage_mb(&self) -> usize
pub fn peak_usage_mb(&self) -> usize
Get peak memory usage in MB.
Sourcepub fn is_available() -> bool
pub fn is_available() -> bool
Check if memory tracking is available on this platform.
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset statistics (for testing).
Trait Implementations§
Source§impl Debug for MemoryGuard
impl Debug for MemoryGuard
Auto Trait Implementations§
impl !Freeze for MemoryGuard
impl RefUnwindSafe for MemoryGuard
impl Send for MemoryGuard
impl Sync for MemoryGuard
impl Unpin for MemoryGuard
impl UnwindSafe for MemoryGuard
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