pub struct DiskSpaceGuard { /* private fields */ }Expand description
Thread-safe disk space guard for monitoring and enforcing disk limits.
Implementations§
Source§impl DiskSpaceGuard
impl DiskSpaceGuard
Sourcepub fn new(config: DiskSpaceGuardConfig) -> Self
pub fn new(config: DiskSpaceGuardConfig) -> Self
Create a new disk space guard with the given configuration.
Sourcepub fn default_guard() -> Self
pub fn default_guard() -> Self
Create a disk space guard with default configuration.
Sourcepub fn with_min_free(min_free_mb: usize) -> Self
pub fn with_min_free(min_free_mb: usize) -> Self
Create a disk space guard with specified minimum free space.
Create an Arc-wrapped disk space guard for sharing across threads.
Sourcepub fn check(&self) -> Result<(), DiskSpaceExhausted>
pub fn check(&self) -> Result<(), DiskSpaceExhausted>
Check disk space limit (returns error if hard limit exceeded).
This should be called periodically during file writes. It’s designed to be efficient - actual disk checks only happen at the configured interval.
Sourcepub fn check_now(&self) -> Result<(), DiskSpaceExhausted>
pub fn check_now(&self) -> Result<(), DiskSpaceExhausted>
Force an immediate disk space check (bypasses interval).
Sourcepub fn check_before_write(
&self,
estimated_bytes: u64,
) -> Result<(), DiskSpaceExhausted>
pub fn check_before_write( &self, estimated_bytes: u64, ) -> Result<(), DiskSpaceExhausted>
Pre-check if there’s enough space for an estimated write.
Sourcepub fn record_write(&self, bytes: u64)
pub fn record_write(&self, bytes: u64)
Record bytes written (for estimation).
Sourcepub fn available_space_mb(&self) -> usize
pub fn available_space_mb(&self) -> usize
Get current available space in MB.
Sourcepub fn is_available() -> bool
pub fn is_available() -> bool
Check if disk space tracking is available on this platform.
Sourcepub fn reset_stats(&self)
pub fn reset_stats(&self)
Reset statistics (for testing).