Struct BatchResult

Source
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

Source

pub fn new() -> Self

Create a new empty batch result

Source

pub fn is_all_success(&self) -> bool

Check if all operations were successful

Source

pub fn success_rate(&self) -> f64

Get success rate as percentage

Source

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

Source§

fn clone(&self) -> BatchResult

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BatchResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BatchResult

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,