pub struct BatchResult {
    pub success_count: usize,
    pub failure_count: usize,
    pub failures: Vec<(String, String)>,
    pub total_bytes: u64,
    pub elapsed_time: Duration,
}Expand description
Batch operation result containing success/failure information
Fields§
§success_count: usizeNumber of successful operations
failure_count: usizeNumber of failed operations
failures: Vec<(String, String)>List of failed items with error messages
total_bytes: u64Total bytes processed
elapsed_time: DurationTotal time taken for the batch operation
Implementations§
Source§impl BatchResult
 
impl BatchResult
Sourcepub fn is_all_success(&self) -> bool
 
pub fn is_all_success(&self) -> bool
Check if all operations were successful
Sourcepub fn success_rate(&self) -> f64
 
pub fn success_rate(&self) -> f64
Get success rate as percentage
Sourcepub fn summary(&self) -> String
 
pub fn summary(&self) -> String
Get formatted summary
Examples found in repository?
examples/batch_operations_demo.rs (line 81)
78fn demonstrate_cache_statistics(batch_ops: &BatchOperations) {
79    match batch_ops.get_cache_statistics() {
80        Ok(result) => {
81            println!("{}", result.summary());
82            println!("Cache analysis:");
83            println!("  - Files processed: {}", result.success_count);
84            println!("  - Total cache size: {}", formatbytes(result.total_bytes));
85            println!(
86                "  - Analysis time: {:.2}ms",
87                result.elapsed_time.as_millis()
88            );
89
90            if result.failure_count > 0 {
91                println!("  - Failed files: {}", result.failure_count);
92                for (file, error) in &result.failures {
93                    println!("    • {file}: {error}");
94                }
95            }
96        }
97        Err(e) => println!("Failed to get cache statistics: {e}"),
98    }
99}
100
101#[allow(dead_code)]
102fn demonstrate_batch_processing(batch_ops: &BatchOperations) {
103    println!("Processing multiple cached files in batch...");
104
105    // Get list of cached files
106    let cached_files = batch_ops.list_cached_files().unwrap_or_default();
107
108    if cached_files.is_empty() {
109        println!("No cached files found for processing");
110        return;
111    }
112
113    println!("Found {} files to process", cached_files.len());
114
115    // Example 1: Validate file sizes
116    println!("\n1. File Size Validation:");
117    let result = batch_ops.batch_process(&cached_files, |name, data| {
118        if data.len() < 10 {
119            Err(format!("File {name} too small ({} bytes)", data.len()))
120        } else {
121            Ok(data.len())
122        }
123    });
124
125    println!("   {}", result.summary());
126    if result.failure_count > 0 {
127        for (file, error) in &result.failures {
128            println!("   ⚠ {file}: {error}");
129        }
130    }
131
132    // Example 2: Content type detection
133    println!("\n2. Content Type Detection:");
134    let result = batch_ops.batch_process(&cached_files, |name, data| {
135        let content_type = detect_content_type(name, data);
136        println!("   {name} -> {content_type}");
137        Ok::<String, String>(content_type)
138    });
139
140    println!("   {}", result.summary());
141
142    // Example 3: Data integrity check
143    println!("\n3. Data Integrity Check:");
144    let result = batch_ops.batch_process(&cached_files, |name, data| {
145        // Simple check: ensure data is not all zeros
146        let all_zeros = data.iter().all(|&b| b == 0);
147        if all_zeros && data.len() > 100 {
148            Err("Suspicious: large file with all zeros".to_string())
149        } else {
150            let checksum = data.iter().map(|&b| b as u32).sum::<u32>();
151            println!("   {name} checksum: {checksum}");
152            Ok(checksum)
153        }
154    });
155
156    println!("   {}", result.summary());
157}
158
159#[allow(dead_code)]
160fn demonstrate_selective_cleanup(batch_ops: &BatchOperations) {
161    println!("Demonstrating selective cache cleanup...");
162
163    // Show current cache state
164    let initial_stats = batch_ops.get_cache_statistics().unwrap();
165    println!(
166        "Before cleanup: {} files, {}",
167        initial_stats.success_count,
168        formatbytes(initial_stats.total_bytes)
169    );
170
171    // Example 1: Clean up temporary files
172    println!("\n1. Cleaning up temporary files (*.tmp):");
173    match batch_ops.selective_cleanup(&["*.tmp"], None) {
174        Ok(result) => {
175            println!("   {}", result.summary());
176            if result.success_count > 0 {
177                println!("   Removed {} temporary files", result.success_count);
178            }
179        }
180        Err(e) => println!("   Failed: {e}"),
181    }
182
183    // Example 2: Clean up old files (demo with 0 days to show functionality)
184    println!("\n2. Age-based cleanup (files older than 0 days - for demo):");
185    match batch_ops.selective_cleanup(&["*"], Some(0)) {
186        Ok(result) => {
187            println!("   {}", result.summary());
188            println!("   (Note: Using 0 days for demonstration - all files are 'old')");
189        }
190        Err(e) => println!("   Failed: {e}"),
191    }
192
193    // Show final cache state
194    let final_stats = batch_ops.get_cache_statistics().unwrap_or_default();
195    println!(
196        "\nAfter cleanup: {} files, {}",
197        final_stats.success_count,
198        formatbytes(final_stats.total_bytes)
199    );
200
201    let freed_space = initial_stats
202        .total_bytes
203        .saturating_sub(final_stats.total_bytes);
204    if freed_space > 0 {
205        println!("Space freed: {}", formatbytes(freed_space));
206    }
207}Trait Implementations§
Source§impl Clone for BatchResult
 
impl Clone for BatchResult
Source§fn clone(&self) -> BatchResult
 
fn clone(&self) -> BatchResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from 
source. Read moreSource§impl Debug for BatchResult
 
impl Debug for BatchResult
Auto Trait Implementations§
impl Freeze for BatchResult
impl RefUnwindSafe for BatchResult
impl Send for BatchResult
impl Sync for BatchResult
impl Unpin for BatchResult
impl UnwindSafe for BatchResult
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts 
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts 
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
 
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
 
impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
 
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct 
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
 
fn is_in_subset(&self) -> bool
Checks if 
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
 
fn to_subset_unchecked(&self) -> SS
Use with care! Same as 
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
 
fn from_subset(element: &SS) -> SP
The inclusion map: converts 
self to the equivalent element of its superset.