Skip to content

Curb indentation hell by macro

Kai A. Hiller requested to merge V02460/fractal:unwrap_or into fractal-next

Highly nested code is a big source of errors and an impairment of readability and maintainability. Especially Rust’s if let destructuring construct is vulnerable to this problem. To help it a bit, this MR adds two macros unwrap_or! and unwrap_or_return! that support avoiding unnecessary indentation in the code.

In the second commit you can see an example use case for each of the macros.

Macros in general hurt readability as the reader has to adapt to an unknown language construct, but I tried to make these two intuitive to use and think it works. The unwrap_or_return! hides the explicit return statement, but due to its bulkiness the macro is hard to overlook and still has return in its name.

Merge request reports