macro_rules! inplace_processor {
($struct_name:ident, $type:ty, $error_type:ty, $process_fn:expr) => { ... };
}Expand description
Creates a stateless, in-place processor that can return an error.
This macro generates a struct that implements the InPlaceProcessor<T, E> trait.
It processes data by mutating it directly and can fail with a specified error type.
§Parameters
$struct_name: The name for the new processor struct.$type: The type of data to be processed (will be passed as&mut).$error_type: The error type for theResult.$process_fn: A function or closure that takes&mut $typeand returns aResult<(), $error_type>.
§Examples
use type_flow_macros::inplace_processor;
use type_flow_traits::InPlaceProcessor;
#[derive(Debug)]
struct MyError;
fn increment(data: &mut i32) -> Result<(), MyError> {
if *data > 100 {
return Err(MyError);
}
*data += 1;
Ok(())
}
inplace_processor!(IncrementProcessor, i32, MyError, increment);
let mut value = 5;
IncrementProcessor::process(&mut value).unwrap();
assert_eq!(value, 6);