Translated to today's Rust, this code looks like:
fn get_cute_cat(img: image_view) -> Option<image_view> {
let cropped = find_cat(img)?;
let with_tie = add_bow_tie(cropped)?;
let with_sparkles = make_eyes_sparkle(with_tie)?;
add_rainbow(make_smaller(with_sparkles))
}
Basically, with the same amount of boilerplate as your exception-based solution, just three ?s. If you prefer, you could also do
fn get_cute_cat(img: image_view) -> Option<image_view> {
find_cat(img).and_then(|cropped|
add_bow_tie(cropped).and_then(|with_tie|
make_eyes_sparkle(with_tie).and_then(|with_sparkles)|
add_rainbow(make_smaller(with_sparkles))
)
)
)
}
... but that has rightward drift issues. I _think_ you could do
fn get_cute_cat(img: image_view) -> Option<image_view> {
find_cat(img)
.and_then(add_bow_tie)
.and_then(make_eyes_sparkle)
.and_then(|with_sparkles|
add_rainbow(make_smaller(with_sparkles))
)
)
}
but I'm not 100% sure without a comparable example.
I bring this up because I don't believe the thing you're seeing is inherent to this style of error-handling, but instead to the language's support for these kinds of monadic patterns. Haskell would look even more succinct than the Rust!