pub fn with_error_scope<S, W, C, T, R, E>(
setup: S,
work: W,
cleanup: C,
) -> Result<R, E>Expand description
Convenience function for scope-aware error handling
This function allows you to handle errors within a scoped operation while still ensuring cleanup happens.
ยงExample
use foundation_utils::scoped::with_error_scope;
let result = with_error_scope(
|| Ok("resource"),
|resource| {
// Work that might fail
if resource.len() > 0 {
Ok(format!("processed: {}", resource))
} else {
Err("empty resource")
}
},
|resource| println!("cleanup: {}", resource)
);