macro_rules! process_images {
() => { ... };
(@vec $images:expr) => { ... };
(@vec $images:expr$(,@with_options $options:expr)?,@var $var:ident,@map $block:block) => { ... };
(@vec $images:expr$(,@with_options $options:expr)?,@map $block:block) => { ... };
(@vec $images:expr$(,@with_options $options:expr)?,@var $var:ident,@for_each $block:block) => { ... };
(@vec $images:expr$(,@with_options $options:expr)?,@for_each $block:block) => { ... };
(@vec $images:expr,@with_options $options:expr) => { ... };
($image:expr) => { ... };
($image:expr,@with_options $options:expr) => { ... };
($($image:expr),+,@with_options $options: expr) => { ... };
($($image:expr),+$(,)?) => { ... };
}Expand description
A macro to process one or more images and return the processed results.
This macro provides flexible ways to process images with various options and automatically handles parallel processing for better performance when dealing with multiple images. It supports both single image processing and batch processing with optional custom options.
For batch processing of more than 10 images, this macro automatically uses parallel processing via the rayon crate to improve performance. For smaller batches or single images, sequential processing is used.
§Arguments
()- Returns an empty vector when called with no arguments$image:expr- Process a single image with default options$image:expr, @with_options $options:expr- Process a single image with custom options$($image:expr),+- Process multiple images with default options$($image:expr),+, @with_options $options:expr- Process multiple images with custom options@vec $images:expr- Process a vector of images with default options@vec $images:expr, @with_options $options:expr- Process a vector of images with custom options@vec $images:expr, @with_options $options:expr, @var $var:ident, @map $block:block- Process a vector of images with custom options and map operation@vec $images:expr, @with_options $options:expr, @var $var:ident, @for_each $block:block- Process a vector of images with custom options and for_each operation@vec $images:expr, @var $var:ident, @map $block:block- Process a vector of images with default options and map operation@vec $images:expr, @var $var:ident, @for_each $block:block- Process a vector of images with default options and for_each operation
§Examples
ⓘ
// Process a single image with default options
let result = process_images!(my_image);
// Process a single image with custom options
let options = ImageProcessorOptions::default()
.option_display_mode(DisplayMode::Ascii)
.get_options();
let result = process_images!(my_image, @with_options options);
// Process multiple images with default options
let results = process_images!(image1, image2, image3);
// or
let results = process_images![image1, image2, image3];
// Process multiple images with custom options
let options = ImageProcessorOptions::default()
.option_resize_mode(ResizeMode::Custom(CustomResizeOption::new(80, 40)))
.get_options();
let results = process_images!(image1, image2, image3, @with_options options);
// Process a vector of images
let image_vec = vec![image1, image2, image3];
let results = process_images!(@vec image_vec);
// Process a vector of images with custom options
let results = process_images!(@vec image_vec, @with_options options);
// Process a vector of images with custom options and map operation
let results = process_images!(@vec image_vec, @with_options options, @var img, @map {
let img = img.unwrap();
println!("Processed image size: {}x{}", img.width, img.height);
img
});
// Process a vector of images with default options and for_each operation
process_images!(@vec image_vec, @var img, @for_each {
let img = img.unwrap();
println!("Processed image size: {}x{}", img.width, img.height);
});
// Return an empty vector
let empty_results: Vec<ImageProcessorResult> = process_images!();§Returns
- For single image processing:
ImageProcessorResult - For multiple image processing:
Vec<ImageProcessorResult> - For empty invocation:
Vec<ImageProcessorResult>(empty vector) - For map operations:
Vec<T>where T is the return type of the map block