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: usize
Number of successful operations
failure_count: usize
Number of failed operations
failures: Vec<(String, String)>
List of failed items with error messages
total_bytes: u64
Total bytes processed
elapsed_time: Duration
Total 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 79)
76fn demonstrate_cache_statistics(batch_ops: &BatchOperations) {
77 match batch_ops.get_cache_statistics() {
78 Ok(result) => {
79 println!("{}", result.summary());
80 println!("Cache analysis:");
81 println!(" - Files processed: {}", result.success_count);
82 println!(" - Total cache size: {}", format_bytes(result.total_bytes));
83 println!(
84 " - Analysis time: {:.2}ms",
85 result.elapsed_time.as_millis()
86 );
87
88 if result.failure_count > 0 {
89 println!(" - Failed files: {}", result.failure_count);
90 for (file, error) in &result.failures {
91 println!(" • {}: {}", file, error);
92 }
93 }
94 }
95 Err(e) => println!("Failed to get cache statistics: {}", e),
96 }
97}
98
99fn demonstrate_batch_processing(batch_ops: &BatchOperations) {
100 println!("Processing multiple cached files in batch...");
101
102 // Get list of cached files
103 let cached_files = batch_ops.list_cached_files().unwrap_or_default();
104
105 if cached_files.is_empty() {
106 println!("No cached files found for processing");
107 return;
108 }
109
110 println!("Found {} files to process", cached_files.len());
111
112 // Example 1: Validate file sizes
113 println!("\n1. File Size Validation:");
114 let result = batch_ops.batch_process(&cached_files, |name, data| {
115 if data.len() < 10 {
116 Err(format!("File {} too small ({} bytes)", name, data.len()))
117 } else {
118 Ok(data.len())
119 }
120 });
121
122 println!(" {}", result.summary());
123 if result.failure_count > 0 {
124 for (file, error) in &result.failures {
125 println!(" ⚠ {}: {}", file, error);
126 }
127 }
128
129 // Example 2: Content type detection
130 println!("\n2. Content Type Detection:");
131 let result = batch_ops.batch_process(&cached_files, |name, data| {
132 let content_type = detect_content_type(name, data);
133 println!(" {} -> {}", name, content_type);
134 Ok::<String, String>(content_type)
135 });
136
137 println!(" {}", result.summary());
138
139 // Example 3: Data integrity check
140 println!("\n3. Data Integrity Check:");
141 let result = batch_ops.batch_process(&cached_files, |name, data| {
142 // Simple check: ensure data is not all zeros
143 let all_zeros = data.iter().all(|&b| b == 0);
144 if all_zeros && data.len() > 100 {
145 Err("Suspicious: large file with all zeros".to_string())
146 } else {
147 let checksum = data.iter().map(|&b| b as u32).sum::<u32>();
148 println!(" {} checksum: {}", name, checksum);
149 Ok(checksum)
150 }
151 });
152
153 println!(" {}", result.summary());
154}
155
156fn demonstrate_selective_cleanup(batch_ops: &BatchOperations) {
157 println!("Demonstrating selective cache cleanup...");
158
159 // Show current cache state
160 let initial_stats = batch_ops.get_cache_statistics().unwrap();
161 println!(
162 "Before cleanup: {} files, {}",
163 initial_stats.success_count,
164 format_bytes(initial_stats.total_bytes)
165 );
166
167 // Example 1: Clean up temporary files
168 println!("\n1. Cleaning up temporary files (*.tmp):");
169 match batch_ops.selective_cleanup(&["*.tmp"], None) {
170 Ok(result) => {
171 println!(" {}", result.summary());
172 if result.success_count > 0 {
173 println!(" Removed {} temporary files", result.success_count);
174 }
175 }
176 Err(e) => println!(" Failed: {}", e),
177 }
178
179 // Example 2: Clean up old files (demo with 0 days to show functionality)
180 println!("\n2. Age-based cleanup (files older than 0 days - for demo):");
181 match batch_ops.selective_cleanup(&["*"], Some(0)) {
182 Ok(result) => {
183 println!(" {}", result.summary());
184 println!(" (Note: Using 0 days for demonstration - all files are 'old')");
185 }
186 Err(e) => println!(" Failed: {}", e),
187 }
188
189 // Show final cache state
190 let final_stats = batch_ops.get_cache_statistics().unwrap_or_default();
191 println!(
192 "\nAfter cleanup: {} files, {}",
193 final_stats.success_count,
194 format_bytes(final_stats.total_bytes)
195 );
196
197 let freed_space = initial_stats
198 .total_bytes
199 .saturating_sub(final_stats.total_bytes);
200 if freed_space > 0 {
201 println!("Space freed: {}", format_bytes(freed_space));
202 }
203}
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§const fn clone_from(&mut self, source: &Self)
const 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 more